Hacker News new | ask | show | jobs
by userbinator 4389 days ago
Extremely simple and straightforward C code too, which is also nice to read. 320ns (on what processor?) is assuming a clock of 2-3GHz on x86 around 1K instructions, several orders of magnitude less than what it was before. But that still works out to a few dozen instructions per character of the string... so I'm inclined to believe that it could go an order of magnitude faster if you really wanted it to, but at that point the Python overhead (PyArg_ParseTuple et al) is going to dominate.

I'm not sure this would be any better than just manually writing out both trivial iterations of the loop:

    for (i = 0; i < 2; i++)
1 comments

I did all the timeit benchmarks on the latest 13" retina MacBook Pro, 2.6 GHz Intel Core i5. The profiler screenshot is from one of our serves on EC2.

Of course there is always potential for optimization, but at this point it's fast enough for our purposes. If you can make it significantly faster please don't hesitate to submit a PR though :)

EDIT: Wouldn't most C compilers unroll the simple "for" loops? Direct link to the C code: https://github.com/elasticsales/ciso8601/blob/master/module....

I don't currently have a use for this library, but I'm going to bookmark it anyways because it looks like a nice introduction to writing a module in C. It does something non trivial but still is simple enough to grok quickly. Thanks!