Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a more efficient Log2 for the uint64 type (#691)
The current practice of converting the uint64 to a float64 and passing it to math.Log2() and then converting the result back to an int is about 18x slower on my M3 MacPro ❯ go test . --fuzz=Fuzz --fuzztime 45s fuzz: elapsed: 0s, gathering baseline coverage: 0/5 completed fuzz: elapsed: 0s, gathering baseline coverage: 5/5 completed, now fuzzing with 12 workers fuzz: elapsed: 3s, execs: 748073 (249310/sec), new interesting: 1 (total: 6) fuzz: elapsed: 6s, execs: 1529140 (260330/sec), new interesting: 1 (total: 6) fuzz: elapsed: 9s, execs: 2306601 (259140/sec), new interesting: 1 (total: 6) fuzz: elapsed: 12s, execs: 3091550 (261720/sec), new interesting: 1 (total: 6) fuzz: elapsed: 15s, execs: 3879652 (262634/sec), new interesting: 1 (total: 6) fuzz: elapsed: 18s, execs: 4659101 (259862/sec), new interesting: 1 (total: 6) fuzz: elapsed: 21s, execs: 5450467 (263818/sec), new interesting: 1 (total: 6) fuzz: elapsed: 24s, execs: 6232258 (260567/sec), new interesting: 1 (total: 6) fuzz: elapsed: 27s, execs: 7016319 (261325/sec), new interesting: 1 (total: 6) fuzz: elapsed: 30s, execs: 7794643 (259510/sec), new interesting: 1 (total: 6) fuzz: elapsed: 33s, execs: 8578148 (261116/sec), new interesting: 1 (total: 6) fuzz: elapsed: 36s, execs: 9360677 (260807/sec), new interesting: 1 (total: 6) fuzz: elapsed: 39s, execs: 10143019 (260780/sec), new interesting: 1 (total: 6) fuzz: elapsed: 42s, execs: 10931666 (262931/sec), new interesting: 1 (total: 6) fuzz: elapsed: 45s, execs: 11717753 (262059/sec), new interesting: 1 (total: 6) fuzz: elapsed: 45s, execs: 11717753 (0/sec), new interesting: 1 (total: 6) PASS ok github.com/OffchainLabs/bold/math 45.854s ❯ go test -bench=. --benchtime=20s goos: darwin goarch: arm64 pkg: github.com/OffchainLabs/bold/math BenchmarkUnsingedIntegerLog2-12 1000000000 0.2990 ns/op BenchmarkMathLog2-12 1000000000 5.414 ns/op PASS ok github.com/OffchainLabs/bold/math 6.991s
- Loading branch information