-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make use of time.clock_gettime_ns() #14
Comments
On my machine,
or more broadly
|
Hm, you are right. My measurements: In [3]: timeit int(time.time() * 1000.0)
74.1 ns ± 0.951 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [4]: timeit time.clock_gettime_ns(time.CLOCK_REALTIME) // 1000000
93.9 ns ± 1.09 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
In [5]: qwe=time.CLOCK_REALTIME
In [6]: timeit time.clock_gettime_ns(qwe) // 1000000
87.1 ns ± 0.426 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each) |
It seems the only cause of slowness is the passing argument for the function. But anyway: reported here: python/cpython#111482 |
Sure - should we use the old micro-optimization tricks of localizing global name lookups we'd probably be a bit faster, but at the expense of not being able to e. g. easily use If you need to generate gazillions of ULIDs as fast as possible, you'd probably want to use a native-code extension instead, eg https://github.com/bdraco/ulid-transform |
Looks like we could use Thanks for the upstream bug report! |
It is faster and without floating point. Just
time.clock_gettime_ns() // 1000000
to get milliseconds.The text was updated successfully, but these errors were encountered: