PiotrDabkowski / Js2Py

JavaScript to Python Translator & JavaScript interpreter written in 100% pure Python🚀 Try it online:
http://piter.io/projects/js2py
MIT License
2.46k stars 260 forks source link

the Library Speed #96

Open mirhmousavi opened 6 years ago

mirhmousavi commented 6 years ago

Js2Py is a fabulous library, really appreciate the makers I want to know how much overhead does js emulated code with this library push to system in comparison to same code in raw python in a scale of one thousand requests per second? If the overhead is so much i want to consider rewrite whole js code base to python

PiotrDabkowski commented 6 years ago

About 50 times slower than a manual translation in the worst case, but on the code I tried it is usually about 10-5 times slower than a manual translation. Also note that Python itself is way slower than JavaScript :) Js2Py is good for projects where the performance is not important or where the translated code is relatively short and does not form a bottleneck.

It is like a debate between C++ vs Python, everything depends on your use case. If you want speed try looking for example at PyExecJs which wraps a real JS engine.

ghost commented 6 years ago

@PiotrDabkowski did you try PyPy ? :)

PiotrDabkowski commented 6 years ago

@Yardanico PyPy will not work because Js2Py sometimes needs to modify the bytecode. But you can try Js2Py VM which is completely separate implementation and can be executed with pypy, see readme.

EDIT: Wow, I have just tested Js2Py VM running on PyPy and the speed of the JS code is comparable to the speed of Python in CPython. To import VM:

from js2py.internals.seval import eval_js_vm
ygl-rg commented 6 years ago

Hi @PiotrDabkowski

I just ran a simple script with js2py.eval_js & pypy2 5.10 and it worked. so I think it is case by case.

johanneswilm commented 5 years ago

@PiotrDabkowski I don't see how I can load an entire JS file and then execute something in its context using eval_js_vm to get to to run faster using pypy. Is this supposed to work or do I have to use the old EvalJS() for that?