Optimal algorithm for testing N prime numbers, written in different languages
The Timer.js file gets the configuration from the config.json file and tests the performance of the languages. Then it saves it in json format
node timer.js 100 # 100 is count of iterations
# or
npm run start 100
yarn start 100
After execute, program will create result.json file
- C
- C++
- Java
- Js
- PHP 7
- Python 3
- Kotlin
- Rust
- Julia
- Go
Step one: Add isPrime algorithm
function isPrime(number) {
for (let i = 2; i <= number / 2; ++i) {
if (number % i == 0) return false;
}
return true;
}
Step two: Add loop with variable number of iterations
for (let i = 100; i > 1; --i) {
isPrime(i);
}
Step three: Change iterations count to __ITERS__
for (let i = __ITERS__; i > 1; --i) {
isPrime(i);
}
Last step: add configuration
Open config.json and add new json object in array.
Possibility configuration:
-
dir - required string, directory with your code
-
run - required string, command that runs your code
-
main - required string, your main file (there is __ITERS__)
-
compile - string, if your code must be compiled this commands should do that