Last active
July 7, 2024 06:33
-
-
Save dwbutler/51657198746c93103e08 to your computer and use it in GitHub Desktop.
Parsing ISO8601 Time format with Ruby
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
| require 'time' | |
| require 'benchmark' | |
| time = Time.now.iso8601(3) | |
| # => "2014-05-26T23:26:08.628-07:00" | |
| Benchmark.bm do |x| | |
| x.report('parse') { 100_000.times { Time.parse(time).gmtime } } | |
| x.report('iso8601') { 100_000.times { Time.iso8601(time).gmtime } } | |
| end | |
| # MRI 2.1.2 | |
| # user system total real | |
| # parse 2.890000 0.050000 2.940000 ( 2.938882) | |
| # iso8601 1.130000 0.010000 1.140000 ( 1.144048) | |
| # JRuby 1.7.12 (Stablized after a few runs) | |
| # user system total real | |
| # parse 4.810000 0.010000 4.820000 ( 4.701000) | |
| # iso8601 0.750000 0.000000 0.750000 ( 0.715000) |
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
| require 'benchmark' | |
| require 'logstash/event' | |
| time = Time.now.iso8601(3) | |
| # => "2014-05-26T23:35:53.961-07:00" | |
| Benchmark.bm do |x| | |
| x.report('joda') { 100_000.times { LogStash::Time.parse_iso8601(time) } } | |
| end | |
| # JRuby 1.7.12 (Stabilized after a few runs) | |
| # user system total real | |
| # joda 0.230000 0.000000 0.230000 ( 0.222000) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried out
Benchmark.bmbmand got similar results. I looked at this gist more closely and noticed that I did already put a comment in there:# JRuby 1.7.12 (Stabilized after a few runs)