Skip to content

Instantly share code, notes, and snippets.

@gogotanaka
Last active August 29, 2015 14:14
Show Gist options
  • Save gogotanaka/379b00397d494a2b22d2 to your computer and use it in GitHub Desktop.
Save gogotanaka/379b00397d494a2b22d2 to your computer and use it in GitHub Desktop.
CRuby, Feature#10785

Ruby, math.c with Fixnum, after r49449

require 'benchmark'

print 'cos   '; puts Benchmark.realtime { 10_000_000.times { Math.cos    1    }}
print 'sin   '; puts Benchmark.realtime { 10_000_000.times { Math.sin    1    }}
print 'tan   '; puts Benchmark.realtime { 10_000_000.times { Math.tan    1    }}
print 'acos  '; puts Benchmark.realtime { 10_000_000.times { Math.acos   1    }}
print 'asin  '; puts Benchmark.realtime { 10_000_000.times { Math.asin   1    }}
print 'atan  '; puts Benchmark.realtime { 10_000_000.times { Math.atan   1    }}
print 'atan2 '; puts Benchmark.realtime { 10_000_000.times { Math.atan2  1, 1 }}
print 'cosh  '; puts Benchmark.realtime { 10_000_000.times { Math.cosh   1    }}
print 'sinh  '; puts Benchmark.realtime { 10_000_000.times { Math.sinh   1    }}
print 'tanh  '; puts Benchmark.realtime { 10_000_000.times { Math.tanh   1    }}
print 'acosh '; puts Benchmark.realtime { 10_000_000.times { Math.acosh  1    }}
print 'asinh '; puts Benchmark.realtime { 10_000_000.times { Math.asinh  1    }}
print 'atanh '; puts Benchmark.realtime { 10_000_000.times { Math.atanh  1    }}
print 'exp   '; puts Benchmark.realtime { 10_000_000.times { Math.exp    1    }}
print 'log   '; puts Benchmark.realtime { 10_000_000.times { Math.log    1, 1 }}
print 'log2  '; puts Benchmark.realtime { 10_000_000.times { Math.log2   1    }}
print 'log10 '; puts Benchmark.realtime { 10_000_000.times { Math.log10  1    }}
print 'sqrt  '; puts Benchmark.realtime { 10_000_000.times { Math.sqrt   1    }}
print 'cbrt  '; puts Benchmark.realtime { 10_000_000.times { Math.cbrt   1    }}
print 'frexp '; puts Benchmark.realtime { 10_000_000.times { Math.frexp  1    }}
print 'ldexp '; puts Benchmark.realtime { 10_000_000.times { Math.ldexp  1, 1 }}
print 'hypot '; puts Benchmark.realtime { 10_000_000.times { Math.hypot  1, 1 }}
print 'erf   '; puts Benchmark.realtime { 10_000_000.times { Math.erf    1    }}
print 'erfc  '; puts Benchmark.realtime { 10_000_000.times { Math.erfc   1    }}
print 'gamma '; puts Benchmark.realtime { 10_000_000.times { Math.gamma  1    }}
print 'lgamma'; puts Benchmark.realtime { 10_000_000.times { Math.lgamma 1    }}

python 3.4.2_1

# for Python3
from benchmarker import Benchmarker
import math

with Benchmarker(10000000, width=15) as bench:
    @bench("cos")
    def _(bm):
        for i in bm: math.cos(1)

    @bench("sin")
    def _(bm):
        for i in bm: math.sin(1)

    @bench("tan")
    def _(bm):
        for i in bm: math.tan(1)

    @bench("acos")
    def _(bm):
        for i in bm: math.acos(1)

    @bench("asin")
    def _(bm):
        for i in bm: math.asin(1)

    @bench("atan")
    def _(bm):
        for i in bm: math.atan(1)

    @bench("atan2")
    def _(bm):
        for i in bm: math.atan2(1, 1)

    @bench("cosh")
    def _(bm):
        for i in bm: math.cosh(1)

    @bench("sinh")
    def _(bm):
        for i in bm: math.sinh(1)

    @bench("tanh")
    def _(bm):
        for i in bm: math.tanh(1)

    @bench("acosh")
    def _(bm):
        for i in bm: math.acosh(1)

    @bench("asinh")
    def _(bm):
        for i in bm: math.asinh(1)

    @bench("atanh")
    def _(bm):
        for i in bm: math.atanh(0)

    @bench("exp")
    def _(bm):
        for i in bm: math.exp(1)

    @bench("log")
    def _(bm):
        for i in bm: math.log(2, 2)

    @bench("log2")
    def _(bm):
        for i in bm: math.log2(1)

    @bench("log10")
    def _(bm):
        for i in bm: math.log10(1)

    @bench("sqrt")
    def _(bm):
        for i in bm: math.sqrt(1)

    @bench("frexp")
    def _(bm):
        for i in bm: math.frexp(1)

    @bench("ldexp")
    def _(bm):
        for i in bm: math.ldexp(1, 1)

    @bench("hypot")
    def _(bm):
        for i in bm: math.hypot(1, 1)

    @bench("erf")
    def _(bm):
        for i in bm: math.erf(1)

    @bench("erfc")
    def _(bm):
        for i in bm: math.erfc(1)

    @bench("gamma")
    def _(bm):
        for i in bm: math.gamma(1)

    @bench("lgamma")
    def _(bm):
        for i in bm: math.lgamma(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment