1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#########################################
# bench_math.rb
#
# Benchmark suite for the Math methods.
#########################################
require "benchmark"
MAX = 100000
Benchmark.bm(35) do |x|
# ACOS
x.report("Math.acos(0)"){
MAX.times{ Math.acos(0) }
}
x.report("Math.acos(1)"){
MAX.times{ Math.acos(1) }
}
x.report("Math.acos(-1)"){
MAX.times{ Math.acos(-1) }
}
# ACOSH
x.report("Math.acosh(0)"){
MAX.times{ Math.acos(0) }
}
x.report("Math.acosh(1)"){
MAX.times{ Math.acos(1) }
}
x.report("Math.acosh(-1)"){
MAX.times{ Math.acos(-1) }
}
# ASIN
x.report("Math.asin(0)"){
MAX.times{ Math.asin(0) }
}
x.report("Math.asin(1)"){
MAX.times{ Math.asin(1) }
}
x.report("Math.asin(-1)"){
MAX.times{ Math.asin(-1) }
}
# ASINH
x.report("Math.asinh(0)"){
MAX.times{ Math.asinh(0) }
}
x.report("Math.asinh(1)"){
MAX.times{ Math.asinh(1) }
}
x.report("Math.asinh(-1)"){
MAX.times{ Math.asinh(-1) }
}
# ATAN
x.report("Math.atan(0)"){
MAX.times{ Math.atan(0) }
}
x.report("Math.atan(1)"){
MAX.times{ Math.atan(1) }
}
x.report("Math.atan(-1)"){
MAX.times{ Math.atan(-1) }
}
# ATANH
x.report("Math.atanh(0)"){
MAX.times{ Math.atanh(0) }
}
x.report("Math.atanh(1)"){
MAX.times{ Math.atanh(1) }
}
x.report("Math.atanh(-1)"){
MAX.times{ Math.atanh(-1) }
}
end
|