podigee/device_detector

Benchmark in the Readme is outdated

Closed this issue · 2 comments

I've ran benchmark from the Readme on my set of real user agents (160k) and it seems that the browser gem is much faster. I didn't compare precision of both though.

Could you compare them with your dataset again?

                      user     system      total        real
device_detector   4.713362   0.000000   4.713362 (  4.714573)
browser           1.780024   0.000000   1.780024 (  1.780048)

Indeed it is.

I didn't do extensive benchmarking but here's some results vs https://github.com/ua-parser/uap-ruby.

This was run on a quad core Intel i5 3.2ghz with an SSD (a desktop workstation from 2014) with Ruby 3.2 (YJIT not enabled):

I ran it against 1 user agent, here's the exact code:

require 'benchmark'
require 'device_detector'
require 'user_agent_parser'

ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'

user_agent_parser = UserAgentParser::Parser.new

Benchmark.bm(30) do |x|
  x.report('device_detector_os') {
    DeviceDetector.new(ua).os_name
  }

  x.report('device_detector_browser') {
    DeviceDetector.new(ua).name
  }

  x.report('device_detector_device_type') {
    DeviceDetector.new(ua).device_type
  }

  x.report('user_agent_parser_os') {
    user_agent_parser.parse(ua).os.to_s
  }

  x.report('user_agent_parser_browser') {
    user_agent_parser.parse(ua).to_s
  }

  x.report('user_agent_parser_device_type') {
    user_agent_parser.parse(ua).device.family
  }
end
                                     user     system      total        real
device_detector_os               0.011413   0.000202   0.011615 (  0.011614)
device_detector_browser          0.039659   0.000005   0.039664 (  0.039668)
device_detector_device_type      0.417399   0.009968   0.427367 (  0.427371)
user_agent_parser_os             0.002138   0.000103   0.002241 (  0.002243)
user_agent_parser_browser        0.002296   0.000112   0.002408 (  0.002411)
user_agent_parser_device_type    0.002017   0.000098   0.002115 (  0.002118)

Hi Cutalion,
Thank you for opening this issue, I had a look at the benchmark and using the code provided on the README I came up with the following numbers:

                      user     system      total        real
device_detector   0.925603   0.020928   0.946531 (  0.948750)
browser           3.555590   0.014877   3.570467 (  3.575951)
useragent         3.264011   0.032327   3.296338 (  3.301772)

                      user     system      total        real
device_detector   0.915578   0.021295   0.936873 (  0.938698)
browser           3.600674   0.022312   3.622986 (  3.635185)
useragent         3.425424   0.054298   3.479722 (  3.500929)

                      user     system      total        real
device_detector   0.916608   0.022739   0.939347 (  0.940993)
browser           3.624404   0.027489   3.651893 (  3.667863)
useragent         3.442139   0.054376   3.496515 (  3.519747)

This was made using the (unreleased) v1.1.2, Ruby v3.1.2 and the following snippet to generate the user agents file:

require 'faker'

File.open('./tmp/user_agent_strings.txt', 'w') do |file|
  200_000.times do
    file.puts(Faker::Internet.user_agent)
  end
end

The README file for the v1.1.2 is updated with the new numbers.