This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
def match_gaskill(formula) | |
return [] unless (match = formula.match(/^\s*(-?\d+(?:\.\d+)?)\s*([+\/*-])\s*(-?\d+(?:\.\d+)?)\s*$/)) | |
return [match[1].to_f, match[2], match[3].to_f] | |
end | |
def match_sweaver(formula) | |
return [] unless (match = formula.match(/(?<operand1>(?:\d+(?:\.\d+)?)|(?:\.\d+))\s*(?<operator>[+\/*-])\s*(?<operand2>(?:\d+(?:\.\d+)?)|(?:\.\d+))/)) | |
return [match[1].to_f, match[2], match[3].to_f] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-darwin14] | |
============================================================ | |
Running tests for obj = 1000000 (Fixnum) | |
user system total real | |
obj: 0.970000 0.000000 0.970000 ( 0.987204) | |
nil_obj: 0.980000 0.010000 0.990000 ( 0.980796) | |
obj.nil?: 1.250000 0.000000 1.250000 ( 1.268564) | |
nil_obj.nil?: 1.280000 0.000000 1.280000 ( 1.287800) | |
!obj: 1.050000 0.000000 1.050000 ( 1.064061) | |
!nil_obj: 1.070000 0.000000 1.070000 ( 1.170393) |