$ time python -c "import json;
for i in range(0, 1000000):
json.loads('{\"data\": \"hello, world\"}')"
real 0m7.055s
user 0m6.951s
sys 0m0.063s
It is no use optimising one part of a system if other parts take 99% of the time.As it stands, the title of the post would be more accurately stated as 'million requests per second with C'.
$ time python -c "import json;
for i in range(0, 1000000):
json.loads('{\"data\": \"hello, world\"}')"
real 0m3.142s
user 0m3.098s
sys 0m0.034s
ujson $ time python -c "import ujson as json;
for i in range(0, 1000000):
json.loads('{\"data\": \"hello, world\"}')"
real 0m0.444s
user 0m0.399s
sys 0m0.028s
Like with many things, it's a question of being smart about your choice of libraries.Also, just because I was curious:
$ time pypy -c "import json;
for i in range(0, 1000000):
json.loads('{\"data\": \"hello, world\"}')"
real 0m0.422s
user 0m0.386s
sys 0m0.032sOf course, most websites aren't dealing with anywhere near that volume of requests, and then Python is fine.
Pypy is interesting, but last time I looked it didn't support C extensions and hence can't be used with the poster's library.
0.291s
Well, that was an easy way to reduce 7 seconds to 0.3.
$ python -m timeit --setup 'import json' "json.loads('{\"data\": \"hello, world\"}')"
100000 loops, best of 3: 9.34 usec per loopJava Golang Rust Scala Maybe C# C
The semi famous techempower benchmarks shows several popular frameworks that can handle over 1mill/sec
My statement was that it could handle the load. Taken into account the fact that the language is built around concurrency, it would handle the load within multiple threads without a hitch.