Last active
June 1, 2017 13:51
-
-
Save wowdyaln/56af2138e4824dd6b929594268c5ba75 to your computer and use it in GitHub Desktop.
how much time does Ruby spend in executing a function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def howmanyPrime(number) | |
dd = 3 | |
dr = 2 | |
output = [] | |
for dd in 3..number | |
for dr in 2..(number-1) | |
if dd%dr == 0 | |
break | |
elsif dr+1 == dd | |
output.push(dd) | |
next | |
end | |
end | |
end | |
return output | |
end | |
# 測時間_1 | |
a = Time.now | |
p howmanyPrime(100000) | |
b = Time.now | |
puts "#{(b-a)*1000} mils" | |
# 測時間_2 | |
require 'benchmark' | |
Benchmark.bm do |x| | |
x.report do | |
p howmanyPrime(100000) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment