require_relative "../lib/nyara/nyara" include Nyara require "benchmark" def cookie1 s res = ParamHash.new s.split(/[,;] */n).reverse_each do |seg| Ext.parse_url_encoded_seg res, seg, false end end def cookie2 s res = ParamHash.new Ext.parse_cookie res, s end history = CGI.escape '历史' s = "pgv_pvi; pgv_si=; pgv_pvi=som; sid=1d6c75f0 ; PLHistory=<#{history}>;" puts Benchmark.measure{ 1000.times{cookie1 s} } puts Benchmark.measure{ 1000.times{cookie2 s} } # cookie2 should be faster