Last active
August 26, 2015 19:19
-
-
Save inkel/e7e6a8b341904b42b13f to your computer and use it in GitHub Desktop.
Benchmarking Ruby performance in Docker Containers
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
/*.log |
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
#! /usr/bin/env bash | |
set -o errexit | |
set -o nounset | |
for tag in alpine ubuntu ruby | |
do | |
docker build -t ruby_performance:${tag} -f Dockerfile.${tag} . | |
done |
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
#! /usr/bin/env ruby | |
require "benchmark/ips" | |
def recursive(n) | |
return 1 if n < 2 | |
recursive(n-1) + recursive(n-2) | |
end | |
def iter(n) | |
a, b = 1, 1 | |
n.times { a, b = b, a+b } | |
a | |
end | |
N = Integer(ARGV.first || 100) | |
puts "Calculating Fibonacci(#{N})" | |
Benchmark.ips do |r| | |
r.report("recursive") { recursive(N) } | |
r.report("iterative") { iter(N) } | |
r.compare! | |
end |
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
FROM alpine:3.2 | |
RUN apk add --update ruby ruby-json \ | |
&& gem install --no-document benchmark-ips | |
ADD *.rb /tmp/ | |
LABEL com.citrusbyte.bits.article=ruby-docker-performance | |
ENTRYPOINT ["ruby"] | |
CMD ["/tmp/benchmark.rb"] |
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
FROM ruby:2.2 | |
RUN gem install --no-ri --no-rdoc benchmark-ips | |
ADD *.rb /tmp/ | |
LABEL com.citrusbyte.bits.article=ruby-docker-performance | |
ENTRYPOINT ["ruby"] | |
CMD ["/tmp/benchmark.rb"] |
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
FROM ubuntu:14.04 | |
RUN apt-get upgrade -y \ | |
&& apt-get install -y ruby2.0 \ | |
&& gem2.0 install --no-ri --no-rdoc benchmark-ips | |
ADD *.rb /tmp/ | |
LABEL com.citrusbyte.bits.article=ruby-docker-performance | |
ENTRYPOINT ["ruby2.0"] | |
CMD ["/tmp/benchmark.rb"] |
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
#! /usr/bin/env ruby | |
require "json" | |
require "time" | |
require "benchmark/ips" | |
NOW = Time.now | |
ISO8601 = NOW.iso8601 | |
PAYLOAD = { timestamp: "2015-08-12T18:17:22-03:00", values: { humidity: 80, temperature: 23 } } | |
Benchmark.ips do |r| | |
r.report("JSON.dump") { JSON.dump(PAYLOAD) } | |
payload = JSON.dump(PAYLOAD) | |
r.report("JSON.parse") { JSON.parse(payload) } | |
r.report("Time#iso8601") { NOW.iso8601 } | |
r.report("Time.iso8601") { Time.iso8601(ISO8601) } | |
end |
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
#! /usr/bin/env bash | |
set -o errexit | |
if [[ -z $1 ]] | |
then | |
echo "Usage: ${0} <peformance|cpuram>" | |
exit 1 | |
fi | |
set -o nounset | |
test=$1 | |
shift | |
for tag in alpine ubuntu ruby | |
do | |
echo "Executing ${test}.rb in ruby_performance:${tag}" | |
docker run --rm ruby_performance:${tag} /tmp/${test}.rb $@ | tee ${tag}.${test}.log | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment