Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do `ns` and `us` stand for in `timeit` result?

Tags:

python

timeit

I was trying to compare performance of two statements with timeit, and the results are something like:

 100 loops, best of 3: 100 ns per loop
 100 loops, best of 3: 1.96 us per loop

But I don't know what these ns and us stands for, so I don't know which one is faster.

like image 474
satoru Avatar asked Aug 05 '12 04:08

satoru


2 Answers

ns stands for nanoseconds. n is the regular SI prefix meaning 10-9. us means microseconds. In SI that would be µs (10-6 seconds) - the u is used because there's not a µ in ASCII, but it does look pretty similar. In your case, that means you're comparing 100×10-9 seconds against 1.96×10-6 seconds - the former is almost 20× faster.

like image 163
Carl Norum Avatar answered Oct 23 '22 08:10

Carl Norum


Nanoseconds and microseconds... 10-9 and 10-6 respectively.

like image 37
Joran Beasley Avatar answered Oct 23 '22 07:10

Joran Beasley