Skip to content

Instantly share code, notes, and snippets.

@kierdavis
Created September 5, 2016 02:31
Show Gist options
  • Save kierdavis/db152906d03ed5995ebedab6847d30fd to your computer and use it in GitHub Desktop.
Save kierdavis/db152906d03ed5995ebedab6847d30fd to your computer and use it in GitHub Desktop.
Benchmark for math.countBits using nimbench
import nimbench
from math import countBits
bench(countBits8, m):
var x = 0
for i in 1..m:
x += countBits(uint8(i))
doNotOptimizeAway(x)
bench(countBits16, m):
var x = 0
for i in 1..m:
x += countBits(uint16(i))
doNotOptimizeAway(x)
bench(countBits32, m):
var x = 0
for i in 1..m:
x += countBits(uint32(i))
doNotOptimizeAway(x)
bench(countBits64, m):
var x = 0
for i in 1..m:
x += countBits(uint64(i))
doNotOptimizeAway(x)
runBenchmarks()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment