Created
January 31, 2012 16:52
-
-
Save ktheory/1711547 to your computer and use it in GitHub Desktop.
Ruby benchmarking
This file contains hidden or 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
#!/usr/bin/env ruby | |
def slow_fib(n) | |
case n | |
when 0, 1 | |
1 | |
else | |
slow_fib(n-1) + slow_fib(n-2) | |
end | |
end | |
puts slow_fib ARGV[0].to_i | |
puts RUBY_RELEASE_DATE |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'benchmark' | |
require 'fileutils' | |
tmp_file = 'hello_world.txt' | |
File.open(tmp_file, "w") {|f| f << "hello world\n" } | |
res = Benchmark.measure do | |
500000.times { rand; File.read(tmp_file) } | |
end | |
puts res.format | |
FileUtils.rm tmp_file | |
# A "slow" system will report high user times: | |
# user 0m6.750s | |
# sys 0m8.650s | |
# A "fast" system: | |
# user 0m4.640s | |
# sys 0m11.380s |
This file contains hidden or 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
#!/bin/bash | |
n=0 | |
until [ $n -eq 100000 ] | |
do | |
#read -n 1 < /dev/random | |
#read < text | |
n=$(( $n + 1)) | |
done |
This file contains hidden or 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
#!/usr/bin/env ruby | |
def curl(url) | |
`curl -s #{url}` | |
end | |
pub_host = curl "instance-data/lapublic-hostname" | |
id = curl "instance-data/latest/meta-data/instance-id" | |
priv_host = `hostname`.strip | |
az = curl "instance-data/latest/meta-data/placement/availability-zone" | |
cpu = `cat /proc/cpuinfo |grep GHz`.split.last | |
puts [priv_host, id, az, cpu].join(',') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment