mgomes / api_auth

HMAC authentication for Rails and HTTP Clients
MIT License
480 stars 147 forks source link

Avoid reallocating static Regexps #82

Closed pd closed 8 years ago

pd commented 8 years ago

This also simplifies the regexp used in parse_uri for stripping the scheme and hostname from a URI.

As before, profiling and/or benchmarking using this script:

https://gist.github.com/pd/df5b38fed1291e82f672

Note the output of "api-auth-1.4.0", which does not exist; I'm just using that as a cheap form of "I built master and wanted to install it separately from the actual gem I use every day."

Benchmark before and after:

$ V=gem M=bench command ruby profile.rb
/Users/khargraves/.gem/ruby/2.2.2/gems/api-auth-1.4.0/lib/api_auth/errors.rb
Calculating -------------------------------------
          authentic?     1.765k i/100ms
-------------------------------------------------
          authentic?     18.406k (± 3.0%) i/s -     37.065k

$ V=local M=bench command ruby profile.rb
/Users/khargraves/sauce/rb/api_auth/lib/api_auth/errors.rb
Calculating -------------------------------------
          authentic?     2.341k i/100ms
-------------------------------------------------
          authentic?     25.007k (± 2.1%) i/s -     51.502k