package benchmark_strings import "base:intrinsics" import "core:fmt" import "core:log" import "core:testing" import "core:strings" import "core:text/table" import "core:time" import "core:unicode/utf8" RUNS_PER_SIZE :: 2500 sizes := [?]int { 7, 8, 9, 15, 16, 17, 31, 32, 33, 63, 64, 65, 95, 96, 97, 128, 256, 512, 1024, 4096, } // These are the normal, unoptimized algorithms. plain_prefix_length :: proc "contextless" (a, b: string) -> (n: int) { _len := min(len(a), len(b)) // Scan for matches including partial codepoints. #no_bounds_check for n < _len && a[n] == b[n] { n += 1 } // Now scan to ignore partial codepoints. if n > 0 { s := a[:n] n = 0 for { r0, w := utf8.decode_rune(s[n:]) if r0 != utf8.RUNE_ERROR { n += w } else { break } } } return } run_trial_size_prefix :: proc(p: proc "contextless" (string, string) -> $R, suffix: string, size: int, idx: int, runs: int, loc := #caller_location) -> (timing: time.Duration) { left := make([]u8, size) right := make([]u8, size) defer { delete(left) delete(right) } if len(suffix) > 0 { copy(left [idx:], suffix) copy(right[idx:], suffix) } else { right[idx] = 'A' } accumulator: int watch: time.Stopwatch time.stopwatch_start(&watch) for _ in 0..