Skip to content

Instantly share code, notes, and snippets.

@ba0f3
Created September 8, 2015 17:18
Show Gist options
  • Save ba0f3/460fdc627cf0476ab1e1 to your computer and use it in GitHub Desktop.
Save ba0f3/460fdc627cf0476ab1e1 to your computer and use it in GitHub Desktop.
Nim empty string initialize benchmarking
import stopwatch
var c1, c2: stopwatch.clock
for a in 1..10:
bench(c1):
for i in 0..1_000_000:
var x = ""
x = "Vietnam"
x = ""
x = "Cong Hoa Xa Hoi Chu Nghia VietNam"
bench(c2):
for i in 0..1_000_000:
var x = newString(0)
x = "Vietnam"
x = newString(0)
x = "Cong Hoa Xa Hoi Chu Nghia VietNam"
echo "bench 1): ", c1.seconds
echo "bench 2): ", c2.seconds
bench 1): 0.168687648s
bench 2): 0.143442351s
bench 1): 0.154993121s
bench 2): -4.143262152s
bench 1): 0.147635408s
bench 2): 0.169453555s
bench 1): 0.16333341s
bench 2): 0.151618036s
bench 1): 0.150937742s
bench 2): 0.148614152s
bench 1): 0.177947353s
bench 2): 0.161993457s
bench 1): 0.17322778s
bench 2): 0.153794209s
bench 1): 0.151196786s
bench 2): 0.148051352s
bench 1): 0.152092145s
bench 2): 0.155017354s
bench 1): 0.14786121s
bench 2): 0.180426113s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment