I wrote a benchmark program by myself in script languages such as C / C ++, Java / Scala, Python / Ruby / JavaScript, and discussed the result of its execution speed, so I will write it.
For the time being, I made a program that outputs test
only 100 ** 3 = 1000000 times.
C++
benchmark.cpp
#include <iostream>
#include <chrono>
using namespace std;
void benchmark();
int main() {
std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
benchmark();
std::chrono::system_clock::time_point end = std::chrono::system_clock::now();
std::cout << "elapsed time: " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() /1000.0 << "[sec]\n";
return 0;
}
void benchmark() {
for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
for (int k = 0; k < 100; k++)
std::cout << "test\n";
}
Compiler: Apple LLVM version 7.3.0 (clang-703.0.31)
elapsed time: 2.076[sec]
Java
benchmark.java
public class benchmark {
public static void main (String[] args) {
long start = System.currentTimeMillis();
benchmark();
long end = System.currentTimeMillis();
System.out.println("elapsed time: " + ((end - start) / 1000.0) + "[sec]");
}
private static void benchmark() {
for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
for (int k = 0; k < 100; k++)
System.out.println("test");
}
}
Compiler: javac 1.8.0_74
elapsed time: 3.581[sec]
Python
benchmark.py
import time
def benchmark():
for i in xrange(100):
for j in xrange(100):
for k in xrange(100):
print 'test'
if __name__ == '__main__':
start = time.time()
benchmark()
end = time.time()
print ("elapsed time: {0}".format(end - start)) + "[sec]"
Version: Python 2.7.11
elapsed time: 2.25964999199[sec]
Recommended Posts