Help us understand the problem. What is going on with this article?

GolangとC++を比較してみた1: for文

なにこれ?

C++を勉強していく過程で、私にとって既知であるGolangと、その実行速度を比較してみようという企画の第1弾です。
早速、ソースコードと実行結果の抜粋を見てみましょう。

Golangのソースコード

main.go
package main

import (
   "fmt"
   "time"
)

func main() {
   start := time.Now()

   for i:=1; i<=100000; i++ {
     if(i % 5000 == 0) {
       fmt.Println(i)
     }
   }

   end := time.Now()

   fmt.Printf("time %f[ms]\n", (end.Sub(start)).Seconds()*1000.0)
}

C++のソースコード

main.cpp
#include <iostream>
#include <time.h>

using namespace std;

int main() {
     clock_t start = clock();

     for(int i=1; i<=100000; i++){
       if(i % 5000 == 0){
         cout << i << endl;
       }
     }

     clock_t end = clock();

     const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
     printf("time %lf[ms]\n", time);

     return 0;
 }

実行結果比較

# Golang
time 0.275946[ms]

#C++
time 0.869000[ms]

終わりに

意外でしょうか?妥当でしょうか?
私自身としては、思ったより差がついたと思いました。
今回は単にfor文を回しただけですので、次回はもっと複雑な処理を実行させて比較したいと思います。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away