Skip to content

Conversation

@rajatsingla
Copy link

Trying to build a regex, by adding all "look_for", Example:-

if we add all "look_for" of "os"(known_type)

"Windows Phone OS|Windows Phone|Symbian|SymbianOS|CrOS|PlayStation|PLAYSTATION|Windows|Series40|iPhone|iPad|BlackBerry|Macintosh|Linux"

Then with this regex we can jump to respective "detector" class on which we have to run detect as appose to iterating.

some profiling:-
With changes

0.00596690177917 // import httpagentparser 

0.000109910964966 // httpagentparser.detect(ua)
         13214 function calls (13037 primitive calls) in 0.006 seconds

without changes

0.00134301185608  // import httpagentparser 

0.000181913375854  // httpagentparser.detect(ua)
         693 function calls in 0.002 seconds

So i am actually making it slower overall

But if u run on in a loop of 100000
with changes

0.00691199302673 // import 
2.00802302361 // loop on httpagentparser.detect(ua)
         3513180 function calls (3513003 primitive calls) in 2.015 seconds

without changes

0.00165581703186 // import 
6.87254285812  //loop on httpagentparser.detect(ua)
         22500469 function calls in 6.874 seconds

There is difference in this case

This idea, i wanted to try out, code is messy but i can clean it a bit if u see potential in it.
But agree, regex is always a little tricky and error prone.

@shon
Copy link
Owner

shon commented Mar 20, 2019

Thanks @rajatsingla :). Will take a look.

@rajatsingla
Copy link
Author

also, ua-parser/uap-python#26

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants