Last active
September 10, 2016 21:47
-
-
Save stopdropandrew/7fa9b1f36dcd3ef528094972d4b6eee8 to your computer and use it in GitHub Desktop.
more optimization!
This file contains hidden or 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
Benchmark.ips do |x| | |
strings = ['android', '1002,60009,30012,60004,20023,10005,10011,50003,10012,50004,10005,30013,60007,10006', '4068B063-0CDF-4579-B4E9-15298ECF9929', 'android', '1002,60009,30012,60004,20023,10005,10011,50003,10012,50004,10005,30013,60007,10006', '4068B063-0CDF-4579-B4E9-15298ECF9929', 'android', '1002,60009,30012,60004,20023,10005,10011,50003,10012,50004,10005,30013,60007,10006', '4068B063-0CDF-4579-B4E9-15298ECF9929'] | |
times = ['2016-08-01 13:00:01+0000', '2016-08-01T13:00:01+0000', '2015-09-27T16:36:45.966+0000'] | |
10.times do | |
times += strings | |
end | |
pt = times.map { |t| Time.parse(t) rescue nil } | |
x.report("match then build w/ iso") do | |
times.each_with_index do |time, i| | |
m = time.match(/^(\d+-\d+-\d+)[T ](\d+:\d+:\d+[.0-9]*)/) | |
next unless m | |
t = Time.iso8601("#{m[1]}T#{m[2]}+00:00") | |
raise unless pt[i] == t | |
end | |
end | |
x.report("match then build w/ new") do | |
times.each_with_index do |time, i| | |
m = time.match(/^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)/) | |
next unless m | |
t = Time.new(*m[1..5], m[6].to_r, 0) | |
raise unless pt[i] == t | |
end | |
end | |
x.report("match then build w/ new + early skip") do | |
times.each_with_index do |time, i| | |
next unless time[4] == '-' && (year = time[0..3].to_i) && year > 2000 | |
m = time.match(/^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)/) | |
t = Time.new(*m[1..5], m[6].to_r, 0) | |
raise unless pt[i] == t | |
end | |
end | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment