LoginSignup
5
4

More than 5 years have passed since last update.

各言語の1秒間のループ回数

Last updated at Posted at 2015-07-14

目的

Rubyは簡潔に記述できる反面、実行速度が遅いと言われている。
また、Rubyで実装した常駐プロセスを動作させた時に他の言語とどのくらい違いが出るのか知りたかったので、計測。

計測用スクリプト/コード

lps.rb
def time_usec( time )
  time.to_i * 1000000 + time.usec
end

sec = ARGV[ 0 ].to_i
sec = 1 if sec <= 0
usec = sec * 1000000

count = 0
start_usec = time_usec( Time.new )
while true
  count += 1
  end_usec = time_usec( Time.new )
  update_usec = end_usec - start_usec
  if usec <= update_usec
    puts "count=#{count} update_usec=#{update_usec}"
    break
  end
end

※各言語に合わせて計測用スクリプト/コードを用意

計測結果

言語 ループ回数 ツール/バージョン
Golang 18,000,000 go 1.4
C言語 17,000,000 gcc 4.2.1
Scala 14,000,000 scala 2.11.4
Node 9,600,000 node 0.8.20
C# 5,300,000 mono 2.10.12
PHP 2,000,000 php 5.5.14
Ruby 600,000 ruby 2.1.5p273
5
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4