Hacker News new | ask | show | jobs
by Someone 1085 days ago
The title should be “optimization-demo” (original title) or “Replacing parts of Python programs by C++ can be easy and profitable”.

They replace Python code that makes 5 calls into native code by code that makes 1 call that makes those 5 calls, and get a speed up from 869k calls per second to 3.15m calls per second, so a snarky title could even be “Python-to-native calls are slow”.

They could even measure it by adding a C++ version of that

  def magic_accept(key: str) -> str:
    return 's3pPLMBiTxaQ9kYGzzhZRbK+xOo='
code and benchmarking that.
1 comments

Did you take a look at the C++ implementation of the hashing function they did? I didn't see a single call made there. They replaced python code that makes 5 calls into a single call.
That's a copy-pasted variation of this public-domain SHA1 code: http://ftp.funet.fi/pub/crypt/hash/sha/sha1.c surrounded by base64 decoding and encoding for a known-length binary text.

By inlining all library code you use, yes indeed, you too can also not make a single call.

I didn’t. I expect that it makes a difference, though for the observation that Python native calls are relatively slow.