Skip to content

Instantly share code, notes, and snippets.

@walf443
Created August 22, 2008 00:44
Show Gist options
  • Save walf443/6679 to your computer and use it in GitHub Desktop.
Save walf443/6679 to your computer and use it in GitHub Desktop.
require 'benchmark'
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
require 'jpmobile'
USER_AGENTS = [
"KDDI-HI31 UP.Browser/6.2.0.5 (GUI) MMP/2.0",
"KDDI-HI31 UP.Browser/6.2.0.5.c.1.100 (GUI) MMP/2.0",
"KDDI-KC31 UP.Browser/6.2.0.5 (GUI) MMP/2.0",
"KDDI-KC22 UP.Browser/6.0.8.3 (GUI) MMP/1.1",
"KDDI-SN31 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0",
"N209i DoCoMo/1.0/N209i DoCoMo/1.0/N209i/c08",
"P209i DoCoMo/1.0/P209i DoCoMo/1.0/P209i/c10",
"P209iS DoCoMo/1.0/P209is DoCoMo/1.0/P209is/c10",
]
COUNT = 1000
def make_random_ua
USER_AGENTS[rand(USER_AGENTS.size).to_i]
end
def mobile user_agent
Jpmobile::Mobile.careers.each do |const|
c = Jpmobile::Mobile.const_get(const)
return c.new(self) if c::USER_AGENT_REGEXP && user_agent =~ c::USER_AGENT_REGEXP
end
nil
end
ua_list = []
COUNT.times do
ua_list.push make_random_ua
end
Benchmark.bm do |x|
x.report 'all career' do
ua_list.each do |ua|
mobile ua
end
end
x.report 'custamize careers' do
Jpmobile::Mobile.careers = [ 'Docomo', 'Au' ]
ua_list.each do |ua|
mobile ua
end
end
end
# user system total real
# all career 0.020000 0.000000 0.020000 ( 0.012653)
# custamize careers 0.000000 0.000000 0.000000 ( 0.006844)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment