Skip to content

Instantly share code, notes, and snippets.

@felipernb
Created February 11, 2011 16:18
Show Gist options
  • Save felipernb/822579 to your computer and use it in GitHub Desktop.
Save felipernb/822579 to your computer and use it in GitHub Desktop.
Benchmark
mustang:~ fribeiro$ time `python -c "print(12345 ** 54321)" > /dev/null`
real 0m22.969s
user 0m22.531s
sys 0m0.059s
mustang:~ fribeiro$ time `ruby -e "puts 12345**54321" > /dev/null`
real 0m10.007s
user 0m9.943s
sys 0m0.022s
mustang:~ fribeiro$ time `php -r "echo bcpow(12345,54321);" > /dev/null`
real 0m4.191s
user 0m4.149s
sys 0m0.026s
mustang:~ fribeiro$ php -r "echo bcpow(12345,54321);" > php.out
mustang:~ fribeiro$ ruby -e "puts 12345**54321" > ruby.out
mustang:~ fribeiro$ python -c "print(12345 ** 54321)" > python.out
mustang:~ fribeiro$ md5 *.out
MD5 (php.out) = b9e70261cddc56351f9e400ec008ca05
MD5 (python.out) = 1089774eed3ff3f524a60d83d1747cf2
MD5 (ruby.out) = 1089774eed3ff3f524a60d83d1747cf2
mustang:~ fribeiro$ file *.out
php.out: ASCII text, with no line terminators
python.out: ASCII text
ruby.out: ASCII text
mustang:~ fribeiro$ ruby -e "puts 12345**54321" > ruby.out
mustang:~ fribeiro$ python -c "print(12345 ** 54321)" > python.out
mustang:~ fribeiro$ php -r "echo bcpow(12345,54321);" > php.out
mustang:~ fribeiro$ echo "" >> php.out
mustang:~ fribeiro$ md5 *.out
MD5 (php.out) = 1089774eed3ff3f524a60d83d1747cf2
MD5 (python.out) = 1089774eed3ff3f524a60d83d1747cf2
MD5 (ruby.out) = 1089774eed3ff3f524a60d83d1747cf2
@jaysonsantos
Copy link

I just tested with pypy which is a python with jit, however for long it is slow for now.

@mazza
Copy link

mazza commented Oct 26, 2011

/*
$ 6g p.go && 6l -o p p.6 && time ./p > /dev/null
real 0m1.882s
user 0m1.809s
sys 0m0.010s
*/

package main

import (
"fmt"
"big"
)

func main() {
x := big.NewInt(12345)
y := big.NewInt(54321)
x.Exp(x, y, nil)
fmt.Println(x)
}

@mazza
Copy link

mazza commented Oct 26, 2011

Go after restart my laptop
real 0m1.760s
user 0m1.748s
sys 0m0.008s

golang

@tonykamillo
Copy link

tony@hitman:~$ python --version && time python -c "print(12345 ** 54321)" > /dev/null
Python 2.7.1+

real 0m1.329s
user 0m1.320s
sys 0m0.010s
tony@hitman:$
tony@hitman:
$
tony@hitman:~$ ruby1.9.1 --version && time ruby1.9.1 -e "puts 12345**54321" > /dev/null
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]

real 0m0.803s
user 0m0.780s
sys 0m0.020s
tony@hitman:$
tony@hitman:
$
tony@hitman:~$ php --version && time php -r "echo bcpow(12345,54321);" > /dev/null
PHP 5.3.5-1ubuntu7.3 with Suhosin-Patch (cli) (built: Oct 13 2011 22:20:48)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

real 0m3.884s
user 0m3.880s
sys 0m0.000s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment