Skip to content

Instantly share code, notes, and snippets.

@flga
Created December 2, 2023 03:25
Show Gist options
  • Save flga/d13a6d82c503fb98dd7b1ab2bc6c38ca to your computer and use it in GitHub Desktop.
Save flga/d13a6d82c503fb98dd7b1ab2bc6c38ca to your computer and use it in GitHub Desktop.
odin regression c12eb3ec933b2415b5d6ca12e173b1fac8c3c847
package main
import "core:fmt"
import "core:runtime"
import "core:time"
PATH_NODE_LEN :: 64
PathNode :: struct {
len: int,
weights: [PATH_NODE_LEN]u64,
}
path_node_search :: proc(node: ^PathNode, target: u64) -> (u64, bool) #no_bounds_check {
len := u64(node.len)
left, right := u64(0), len
for left < right {
midpoint := (left + right) / 2
if node.weights[midpoint] < target {
left = midpoint + 1
} else {
right = midpoint
}
}
return left, left < len
}
path_node_insert :: proc(node: ^PathNode, pos: u64) {
child_index, ok := #force_inline path_node_search(node, pos)
if !ok {
panic("??")
}
}
main :: proc() {
count :: 1_000_000
node := new(PathNode)
node.weights[PATH_NODE_LEN - 1] = 43
node.len = PATH_NODE_LEN
context.user_ptr = node
opts := time.Benchmark_Options {
count = count,
processed = count,
bench = proc(options: ^time.Benchmark_Options, allocator: runtime.Allocator) -> (err: time.Benchmark_Error) {
node := (^PathNode)(context.user_ptr)
for i := 0; i < options.count; i += 1 {
#force_no_inline path_node_insert(node, 42)
}
return nil
},
}
time.benchmark(&opts)
fmt.printf("%.02f\n", opts.rounds_per_second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment