Created
March 24, 2017 20:49
-
-
Save filiptepper/cfacc53fc83a09a2cc2837279f508a56 to your computer and use it in GitHub Desktop.
Time benchmarks.rb
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 "bundler/inline" | |
require "time" | |
require "date" | |
gemfile(true) do | |
source "https://rubygems.org/" | |
gem "benchmark-ips", require: "benchmark/ips" | |
end | |
time = "2017-02-28 14:07:15+0000" | |
Benchmark.ips do |x| | |
x.config warmup: 100 if RUBY_PLATFORM == "java" | |
x.report(%q{Time.strptime(time, "%Y-%m-%d %H:%M:%S%z").strftime("%s")}) do | |
Time.strptime(time, "%Y-%m-%d %H:%M:%S%z").strftime("%s") | |
end | |
x.report(%q{DateTime.strptime(time, "%Y-%m-%d %H:%M:%S%z").strftime("%s")}) do | |
DateTime.strptime(time, "%Y-%m-%d %H:%M:%S%z").strftime("%s") | |
end | |
x.report(%q{Time.strptime(time, "%Y-%m-%d %H:%M:%S%z").to_i}) do | |
Time.strptime(time, "%Y-%m-%d %H:%M:%S%z").to_i | |
end | |
x.report(%q{DateTime.strptime(time, "%Y-%m-%d %H:%M:%S%z").to_i}) do | |
DateTime.strptime(time, "%Y-%m-%d %H:%M:%S%z").to_time.to_i | |
end | |
x.report(%q{DateTime.parse(time).to_time.to_i}) do | |
DateTime.parse(time).to_time.to_i | |
end | |
x.report(%q{Time.parse(time).to_i}) do | |
Time.parse(time).to_i | |
end | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment