3 ms·
json: $ time python -c "import json; for i in range(0, 1000000): json.loads('{\"data\": \"hello, world\"}')" real 0m3.142s user 0m3.
by Twirrim 10y ago
json:
$ 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.032s
- pg314 10y agoIf you use a C library and have hardly any Python code running it obviously goes faster. That misses the point I was making. At some point you'll have to write some Python code, and that will lower the number of requests dramatically. If you're talking millions of requests per second, you will have maybe 10s of thousands of CPU cycles per request. That doesn't buy you much in Python. Case in point: parsing a trivial json string in Python eats up your budget. Of 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.