Τρίτη 3 Μαΐου 2022

Java vs c++ vs python

3.000.000.000 c++ iterations at:6 sec
9.000.000.000 java iterations at :2 sec
0.123.456.789 python iterations at : 9.88  sec

ok i understand python is too slow but how is this possible and
java is faster than c++ (on my ubuntu 20.01) ????????

3.400.000.000 Hz = 3.4GHz


 

 

 

 

 

 

 

 

( This new idea-stream of
teachers proposing python to kids is beyond...
............my understanding !!!!
Maybe its because they forgot their programming learning progress .
----python....go interprette your self !!!!!)

 

#include <iostream>
#include<ctime>
#include <sstream>
using namespace std;
int main(int argc, char** argv){
    cout<<"Hello c++ Universe" <<endl;
     long iterations=300000000l;//3.000.000.000
       if(argc>1){
        stringstream buffer(argv[1]);
        buffer >> iterations;
        }
    long l=iterations;
    time_t startTime=time(NULL);
    while(l>0){
        //std::cout << l << std::endl;
        l-=1;
    }
    time_t endTime=time(NULL);
    double difTime=endTime-startTime;
    cout<<iterations<<" c++ iterations at:"<<difTime<<" sec"<<endl;
    return 0;
}//g++ -o CppDecreaser CppDecreaser.cpp -> ./CppDecreaser 1234


public class JavaDecreaser{
    public static void main(String args[]){
        long iterations=9000000000l ; //~=3.000.000.000 actions per second
        if(args.length>0){
            try{iterations=Long.parseLong(args[0]);}catch(NumberFormatException nfe){}
        }
        long l=iterations;
        long startTime=System.currentTimeMillis();
        while(l>0){
            //System.out.println(l+"");
            l-=1;
        }
        long endTime=System.currentTimeMillis();
        long difTime=endTime-startTime;
        System.out.println(iterations+" java iterations at :"+(difTime/1000)+" sec" );
    }
}//javac JavaDecreaser.java -> java JavaDecreaser 1234


import sys
import time
iterations = 300000000#0
if(len(sys.argv)>1):
    iterations=int(sys.argv[1])
l=iterations
startTime=time.time()
while(l>0):
    #print(l)
    l-=1
endTime=time.time()
difTime=endTime-startTime
print(iterations," python iterations at :",difTime," sec")
#python or python3 PythonDecreaser 1234


Hello c++ Universe
3000000000 c++ iterations at:6 sec
9000000000 java iterations at :2 sec
123456789  python iterations at : 10.401030540466309  sec


Δεν υπάρχουν σχόλια: