Skip to content

Instantly share code, notes, and snippets.

@hhatto
Last active November 21, 2017 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhatto/c951a981e8a3ee4d1bbcf96cb93d5f5e to your computer and use it in GitHub Desktop.
Save hhatto/c951a981e8a3ee4d1bbcf96cb93d5f5e to your computer and use it in GitHub Desktop.
benchmark script for user-agent string parser
from benchmarker import Benchmarker
from ua_parser import user_agent_parser as uap_parser
from woothee import parse as woothee_parse
from fast_woothee import parse as fw_parse
ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36'
n = 1000 * 100
with Benchmarker(n) as bench:
@bench("uap")
def _uap(bm):
parse = uap_parser.Parse
for i in bm:
parse(ua)
@bench("uap(non-cache)")
def _uap_noncache(bm):
parser = uap_parser.ParseUserAgent
for i in bm:
parser(ua)
@bench("woothee")
def _woothee(bm):
parse = woothee_parse
for i in bm:
parse(ua)
@bench("fast-woothee")
def _fast_woothee(bm):
parse = fw_parse
for i in bm:
parse(ua)
@hhatto
Copy link
Author

hhatto commented Sep 1, 2017

## benchmarker:         release 4.0.1 (for python)
## python version:      2.7.13
## python compiler:     GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)
## python platform:     Darwin-15.6.0-x86_64-i386-64bit
## python executable:   ./.virtualenvs/py2713/bin/python
## cpu model:           Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
## parameters:          loop=100000, cycle=1, extra=0

##                                       real    (total    = user    + sys)
uap                                    0.0813    0.0800    0.0800    0.0000
uap(non-cache)                        64.3114   63.5200   63.2800    0.2400
woothee                                3.2219    3.1200    3.1000    0.0200
fast-woothee                           1.0989    1.1000    1.0900    0.0100

## Ranking                               real
uap                                    0.0813  (100.0) ********************
fast-woothee                           1.0989  (  7.4) *
woothee                                3.2219  (  2.5) *
uap(non-cache)                        64.3114  (  0.1)

## Matrix                                real    [01]    [02]    [03]    [04]
[01] uap                               0.0813   100.0  1352.1  3964.4 79132.1
[02] fast-woothee                      1.0989     7.4   100.0   293.2  5852.5
[03] woothee                           3.2219     2.5    34.1   100.0  1996.1
[04] uap(non-cache)                   64.3114     0.1     1.7     5.0   100.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment