From: Stephen Smith <4fires@...> Date: 2007-03-31T05:09:52+09:00 Subject: Re: text processing ------=_Part_88384_13506395.1175285389604 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Sweet! Thanks James. This will probably help quite a bit as our user base (fingers crossed) grows. :-) Steve On 3/30/07, James Edward Gray II wrote: > > On Mar 30, 2007, at 2:31 PM, Stephen Smith wrote: > > > But I think that the format Harry and Gary suggested clearly > > represents the pattern I'm matching. > > Just FYI, when speed matters it may be worth using unpack: > > #!/usr/bin/env ruby -w > > require "benchmark" > > TESTS = 100_000 > LINE = "XYZ" * 100 > Benchmark.bmbm do |results| > results.report("regex:") do > TESTS.times do > /(.{8})(.{6})(.{15})(.{3})(.{30})(.{4})(.{15})(.{1})(.{12})(. > {9})/.match(LINE).captures.join(",") > end > end > results.report("unpack:") do > TESTS.times do > LINE.unpack("A8A6A15A3A30A4A15A1A12A9").join(",") > end > end > end > # >> Rehearsal ------------------------------------------- > # >> regex: 2.060000 0.000000 2.060000 ( 2.067150) > # >> unpack: 0.760000 0.000000 0.760000 ( 0.762482) > # >> ---------------------------------- total: 2.820000sec > # >> > # >> user system total real > # >> regex: 2.040000 0.000000 2.040000 ( 2.046938) > # >> unpack: 0.770000 0.000000 0.770000 ( 0.763620) > > __END__ > > James Edward Gray II > > ------=_Part_88384_13506395.1175285389604--