Created
June 14, 2012 08:03
-
-
Save joel/2928905 to your computer and use it in GitHub Desktop.
Time comparison ActiveSupport vs Gem Twitter Static Time Constants w Ruby Prof
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
require 'rubygems' | |
# Set up gems listed in the Gemfile. | |
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', __FILE__) | |
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) | |
require 'rails/all' | |
require 'time_constants' | |
require 'ruby-prof' | |
N = 1000000 | |
to = Time.local(2008, 12, 27, 14, 30, 59) | |
from = Time.local(2008, 12, 29, 14, 30, 59) | |
results = RubyProf.profile do | |
age = from.to_i - Time.now.to_i | |
case | |
when age < T_7_DAYS | |
'green' # Normally | |
when age > T_15_DAYS | |
'red' # Critical | |
else | |
'orange' # On transition | |
end | |
end | |
prefix = 'twitter-time-constants' | |
File.open "#{prefix}-profile-graph.html", 'w' do |file| | |
RubyProf::GraphHtmlPrinter.new(results).print(file) | |
end | |
File.open "#{prefix}-profile-flat.txt", 'w' do |file| | |
RubyProf::FlatPrinter.new(results).print(file) | |
end | |
File.open "#{prefix}-profile-tree.prof", 'w' do |file| | |
RubyProf::CallTreePrinter.new(results).print(file) | |
end | |
results = RubyProf.profile do | |
age = from.day - Time.now.day | |
case | |
when age < 7 | |
'green' # Normally | |
when age > 15 | |
'red' # Critical | |
else | |
'orange' # On transition | |
end | |
end | |
prefix = 'activesupport-time-calculation' | |
File.open "#{prefix}-profile-graph.html", 'w' do |file| | |
RubyProf::GraphHtmlPrinter.new(results).print(file) | |
end | |
File.open "#{prefix}-profile-flat.txt", 'w' do |file| | |
RubyProf::FlatPrinter.new(results).print(file) | |
end | |
File.open "#{prefix}-profile-tree.prof", 'w' do |file| | |
RubyProf::CallTreePrinter.new(results).print(file) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment