regex - performance grep vs perl -ne -
i made performance test surprising result: perl more 20 times faster!
is normal? result regular expression? egrep far slower grep? ... tested on current cygwin , current opensuse 13.1 in virtualbox.
fastest test perl:
time zcat log.gz \ | perl -ne 'print if ($_ =~ /^\s+\s+\s+\s+(error|warning|severe)\s/ )' | tail 2014-06-24 14:51:43,929 severe ajp-0.0.0.0-8009-13 sessiondataupdatemanager cannot register active info when window has no name 2014-06-24 14:52:01,031 error hfn si threadpool(4)-442 cepeventunmarshaler unmarshaled events duration: 111 2014-06-24 14:52:03,556 error hfn si threadpool(4)-444 cepeventunmarshaler unmarshaled events duration: 52 2014-06-24 14:52:06,789 severe ajp-0.0.0.0-8009-1 sessiondataupdatemanager cannot register active info when window has no name 2014-06-24 14:52:06,792 severe ajp-0.0.0.0-8009-1 sessiondataupdatemanager cannot register active info when window has no name 2014-06-24 14:52:07,371 severe ajp-0.0.0.0-8009-9 sessiondataupdatemanager cannot register active info when window has no name 2014-06-24 14:52:07,373 severe ajp-0.0.0.0-8009-9 sessiondataupdatemanager cannot register active info when window has no name 2014-06-24 14:52:07,780 severe ajp-0.0.0.0-8009-11 sessiondataupdatemanager cannot register active info when window has no name 2014-06-24 14:52:07,782 severe ajp-0.0.0.0-8009-11 sessiondataupdatemanager cannot register active info when window has no name 2014-06-24 15:06:24,119 error hfn si threadpool(4)-443 cepeventunmarshaler unmarshaled events duration: 117 real 0m0.151s user 0m0.062s sys 0m0.139s fine!
far slower test egrep:
time zcat log.gz \ | egrep '^\s+\s+\s+\s+(error|warning|severe)\s' | tail ... real 0m2.454s user 0m2.448s sys 0m0.092s (output same above...)
finally slower grep different notation (my first try)
time zcat log.gz \ | egrep '^[^\s]+\s+[^\s]+\s+(error|warning|severe)\s' | tail ... real 0m4.295s user 0m4.272s sys 0m0.138s (output same above...)
the ungzipped file size 2.000.000 lines un-gzip-ped 500mbytes - matching line count small.
my tested versions:
opensuse grep (gnu grep) 2.14 cygwin grep (gnu grep) 2.16perhaps bug newer grep versions?
you tricked operating system's cache. when reading , grepping files layers filesystem walked through:
harddrive own cache os read cacheto know what's going on it's thought warm these caches running tests work not count. after these test stop runnning time.
regex perl grep
No comments:
Post a Comment