https://github.com/vitkarpov/cpp-vs-javascript
C++ vs Javascript V8 performance
https://github.com/vitkarpov/cpp-vs-javascript
Last synced: about 2 months ago
JSON representation
C++ vs Javascript V8 performance
- Host: GitHub
- URL: https://github.com/vitkarpov/cpp-vs-javascript
- Owner: vitkarpov
- Created: 2015-02-07T21:36:12.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-02-07T21:36:25.000Z (about 10 years ago)
- Last Synced: 2025-01-17T23:19:42.543Z (3 months ago)
- Language: C++
- Size: 102 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# C++ vs Javascript V8 performance
There're two exactly the same solutions of the same problem written on c++ and javascript. By the light of nature c++ code should work much more faster. However it could be not truth.
## The problem
Compute the 25.000th prime
## The algorithm
Iterate over all natural numbers and check if the number on each step is not devisable by any members of any initially empty list of primes, add x to the list until we have 25.000
## The results
```
$> time ./primes287107
real 0m1.779s
user 0m1.775s
sys 0m0.003s
``````
$> time node primes.js287107
real 0m1.186s
user 0m1.173s
sys 0m0.019s
``````
process.versions{
...
v8: '3.14.5.9',
...
}
```Version of v8 were used: *3.14.5.9*
## Illation
Javascript could be really fast but you should use it properly. It's necessary to know v8's basic concepts, such as hidden classes and so forth.
[Google I/O 2012 - Breaking the JavaScript Speed Limit with V8](http://www.youtube.com/watch?v=UJPdhx5zTaw)