Merge core:simd/util into core:bytes

This commit is contained in:
Feoramund
2024-08-10 07:17:03 -04:00
parent e7e7fe766a
commit c69fa87d53
8 changed files with 164 additions and 246 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
package benchmarks
@(require) import "bytes"
@(require) import "crypto"
@(require) import "hash"
@(require) import "simd/util"
@@ -1,15 +1,15 @@
package benchmark_simd_util
package benchmark_bytes
import "core:bytes"
import "core:fmt"
import "core:log"
import simd_util "core:simd/util"
import "core:testing"
import "core:time"
// These are the normal, unoptimized algorithms.
plain_index_byte :: proc "contextless" (s: []u8, c: byte) -> (res: int) #no_bounds_check {
plain_index_byte :: proc(s: []u8, c: byte) -> (res: int) #no_bounds_check {
for i := 0; i < len(s); i += 1 {
if s[i] == c {
return i
@@ -18,7 +18,7 @@ plain_index_byte :: proc "contextless" (s: []u8, c: byte) -> (res: int) #no_boun
return -1
}
plain_last_index_byte :: proc "contextless" (s: []u8, c: byte) -> (res: int) #no_bounds_check {
plain_last_index_byte :: proc(s: []u8, c: byte) -> (res: int) #no_bounds_check {
for i := len(s)-1; i >= 0; i -= 1 {
if s[i] == c {
return i
@@ -37,7 +37,7 @@ sizes := [?]int {
1024 * 1024 * 1024,
}
run_trial_size :: proc(p: proc "contextless" ([]u8, byte) -> int, size: int, idx: int, warmup: int, runs: int) -> (timing: time.Duration) {
run_trial_size :: proc(p: proc([]u8, byte) -> int, size: int, idx: int, warmup: int, runs: int) -> (timing: time.Duration) {
data := make([]u8, size)
defer delete(data)
@@ -95,9 +95,9 @@ benchmark_plain_index_hot :: proc(t: ^testing.T) {
benchmark_simd_index_cold :: proc(t: ^testing.T) {
report: string
for size in sizes {
timing := run_trial_size(simd_util.index_byte, size, size - 1, 0, 1)
timing := run_trial_size(bytes.index_byte, size, size - 1, 0, 1)
report = fmt.tprintf("%s\n +++ % 8M | %v", report, size, timing)
timing = run_trial_size(simd_util.last_index_byte, size, 0, 0, 1)
timing = run_trial_size(bytes.last_index_byte, size, 0, 0, 1)
report = fmt.tprintf("%s\n (last) +++ % 8M | %v", report, size, timing)
}
log.info(report)
@@ -107,9 +107,9 @@ benchmark_simd_index_cold :: proc(t: ^testing.T) {
benchmark_simd_index_hot :: proc(t: ^testing.T) {
report: string
for size in sizes {
timing := run_trial_size(simd_util.index_byte, size, size - 1, HOT, HOT)
timing := run_trial_size(bytes.index_byte, size, size - 1, HOT, HOT)
report = fmt.tprintf("%s\n +++ % 8M | %v", report, size, timing)
timing = run_trial_size(simd_util.last_index_byte, size, 0, HOT, HOT)
timing = run_trial_size(bytes.last_index_byte, size, 0, HOT, HOT)
report = fmt.tprintf("%s\n (last) +++ % 8M | %v", report, size, timing)
}
log.info(report)