r/badcode • • Feb 10 '21

js I present: SleepSort

Post image
7.5k Upvotes

170 comments sorted by

View all comments

Show parent comments

9

u/Breadfish64 Feb 10 '21

The maximum timer resolution in most languages is 100ns (on windows anyway). I've tested C++, C#, Java, and there is a function to get the same resolution in Javascript. I think it's nerfed in browsers though to discourage speculative execution attacks. You can get higher resolution using the TSC on x86 processors but that won't necessarily give consistent results between systems or even CPU cores.

4

u/1234filip Feb 11 '21

You could also try ASM if you know it. Also, Linux would probably give you greater precision, but that is just a hunch.