Why does JavaScript appear to be 4 times faster than C++?

前端 未结 5 1799
长发绾君心
长发绾君心 2021-01-29 22:42

For a long time, I had thought of C++ being faster than JavaScript. However, today I made a benchmark script to compare the speed of floating point calculations in the two langu

5条回答
  •  时光说笑
    2021-01-29 23:45

    This is a polarizing topic, so one may have a look at:

    https://benchmarksgame-team.pages.debian.net/benchmarksgame/

    Benchmarking all kinds of languages.

    Javascript V8 and such are surely doing a good job for simple loops as in the example, probably generating very similar machine code. For most "close to the user" applications Javscript surely is the better choice, but keep in mind the memory waste and the many times unavoidable performance hit (and lack of control) for more complicated algorithms/applications.

提交回复
热议问题