Skip to content

Instantly share code, notes, and snippets.

@dresswithpockets
Last active March 15, 2022 18:02
Show Gist options
  • Save dresswithpockets/4d1910d0d11c70b78191cb1604af1b1f to your computer and use it in GitHub Desktop.
Save dresswithpockets/4d1910d0d11c70b78191cb1604af1b1f to your computer and use it in GitHub Desktop.
Windows 10 x64
Radeon 1500x (8 CPUs) ~3.5 GHz
./main.exe
[1M Iterations Internal Lerp] 1000000 rounds in 28827000 ns
34689700.628 rounds/s
[100M Iterations Internal Lerp] 100000000 rounds in 2900400700 ns
34477994.713 rounds/s
[1M Iterations Custom Lerp] 1000000 rounds in 21413900 ns
46698639.669 rounds/s
[100M Iterations Custom Lerp] 100000000 rounds in 2120838900 ns
47151153.254 rounds/s
package main
import "core:fmt"
import "core:math"
import "core:math/linalg"
import "core:time"
lerp :: proc "contextless" (a, b: $T, t: $E) -> (x: T) { return a + (b - a) * t }
main :: proc() {
run_benchmarks()
}
run_benchmarks :: proc() {
name := "1M Iterations Internal Lerp"
options := &time.Benchmark_Options{
rounds = 1_000_000,
bench = bench_internal_lerp,
}
err := time.benchmark(options, context.allocator)
benchmark_print(name, options)
name = "100M Iterations Internal Lerp"
options.rounds = 100_000_000
err = time.benchmark(options, context.allocator)
benchmark_print(name, options)
name = "1M Iterations Custom Lerp"
options.rounds = 1_000_000
options.bench = bench_custom_lerp
err = time.benchmark(options, context.allocator)
benchmark_print(name, options)
name = "100M Iterations Custom Lerp"
options.rounds = 100_000_000
err = time.benchmark(options, context.allocator)
benchmark_print(name, options)
}
bench_internal_lerp :: proc(options: ^time.Benchmark_Options, allocator := context.allocator) -> (err: time.Benchmark_Error) {
v3: linalg.Vector2f64
for i in 0..=options.rounds {
i_f64 := f64(i)
v1 := linalg.Vector2f64{i_f64*1,i_f64*1.1}
v2 := linalg.Vector2f64{i_f64*1.2,i_f64*1.3}
v3 = math.lerp(v1, v2, (i_f64 / f64(options.rounds)))
}
options.count = options.rounds
return .Okay
}
bench_custom_lerp :: proc(options: ^time.Benchmark_Options, allocator := context.allocator) -> (err: time.Benchmark_Error) {
v3: linalg.Vector2f64
for i in 0..=options.rounds {
i_f64 := f64(i)
v1 := linalg.Vector2f64{i_f64*1,i_f64*1.1}
v2 := linalg.Vector2f64{i_f64*1.2,i_f64*1.3}
v3 = lerp(v1, v2, (i_f64 / f64(options.rounds)))
}
options.count = options.rounds
return .Okay
}
benchmark_print :: proc(name: string, options: ^time.Benchmark_Options) {
fmt.printf("\t[%v] %v rounds in %v ns\n\t\t%5.3f rounds/s\n",
name,
options.rounds,
time.duration_nanoseconds(options.duration),
options.rounds_per_second,
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment