Ranking of running speeds of various programming languages - dividing 7 by 1 billion times to find the number with a remainder of 0


The best way is to run it 10 times, take the average, and display the elapsed seconds to 3 decimal places.
Because it is the first time to open it, maybe the CPU has not been optimized yet, so it is more accurate to take the average multiple times. The
first time is 10 times, it takes 3 seconds, the average is 3 seconds.
The second time is 10 times, it takes 4 seconds, the average is 3.5 seconds.


I mainly study the same function, the same algorithm, different programming languages, which one runs faster

Question: Why do you need to find multiples of 7?
For example, if there are 1 billion additions, which one of 40 programming languages ​​is faster?
It is to find an algorithm to compare the speed difference of different programming languages.
For example, if there are 1 billion additions, which one of 40 programming languages ​​will be faster?

For example, VB6 takes 2 seconds, Yi Language takes 36 seconds, LUA takes 70 seconds, and keystrokes take 10,000 to 50,000 seconds.

js web page test:

<body>
Javascript-10亿次求余数计算测试,7的整数个数有多少?</br>

<script type='text/javascript'>
var count=1000*1000*1000;
var testcount=10;
var alltime=0;
var t=0;



var int = self.setInterval("clock()", 1);
function clock() {
    t += 1;
    if (t == 1) {
        document.write("Javascript-10亿次求余数计算测试,7的整数个数有多少?测试次数:" + testcount + "</br></br>");
    }

    var c = 0;
    var begin = new Date();
    for (var i = 0; i < count; i++) {
        if (i % 7 == 0) c += 1;
    }
    var end = new Date();
    var usedtime = end - begin;
    alltime = alltime + usedtime;
    document.write("第" + t + "次/" + testcount + ",JS用时=" + usedtime + "毫秒,找到数量:" + c + "</br>");

    if (t == testcount) {
        int = window.clearInterval(int);
        document.write("</br>测试" + testcount + "次,总用时=" + (alltime / 1000).toFixed(4) + "秒,平均速度" + (alltime / 1000 / testcount).toFixed(4) + "秒");
    }

} //function  clock

</script>
</body>

おすすめ

転載: blog.csdn.net/xiaoyao961/article/details/132412020