Created
December 18, 2017 09:29
-
-
Save jodosha/b160624e6a755bf140467a888c00deac to your computer and use it in GitHub Desktop.
Ruby string interpolation bench: annotated vs unannotated (http://rubocop.readthedocs.io/en/latest/cops_style/#styleformatstringtoken)
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
#!/usr/bin/env ruby | |
require 'benchmark/ips' | |
require 'bundler/setup' | |
require 'dnsimple' | |
account_id = 1010 | |
zone_id = 100 | |
record_id = 999 | |
Benchmark.ips do |x| | |
x.report("unannotated") { Dnsimple::Client.versioned("/%s/zones/%s/records/%s" % [account_id, zone_id, record_id]) } | |
x.report("annotated") { Dnsimple::Client.versioned("/%<account_id>s/zones/%<zone_id>s/records/%<record_id>s" % {account_id: account_id, zone_id: zone_id, record_id: record_id}) } | |
x.compare! | |
end | |
__END__ | |
Result: | |
Warming up -------------------------------------- | |
unannotated 40.723k i/100ms | |
annotated 29.192k i/100ms | |
Calculating ------------------------------------- | |
unannotated 469.618k (± 2.8%) i/s - 2.362M in 5.033355s | |
annotated 312.024k (± 4.5%) i/s - 1.576M in 5.062552s | |
Comparison: | |
unannotated: 469618.4 i/s | |
annotated: 312023.6 i/s - 1.51x slower | |
Ruby: | |
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16] | |
Hardware: | |
Hardware Overview: | |
Model Name: MacBook Pro | |
Model Identifier: MacBookPro12,1 | |
Processor Name: Intel Core i7 | |
Processor Speed: 3,1 GHz | |
Number of Processors: 1 | |
Total Number of Cores: 2 | |
L2 Cache (per Core): 256 KB | |
L3 Cache: 4 MB | |
Memory: 16 GB | |
Boot ROM Version: MBP121.0171.B00 | |
SMC Version (system): 2.28f7 | |
Software: | |
System Software Overview: | |
System Version: macOS 10.12.6 (16G1114) | |
Kernel Version: Darwin 16.7.0 | |
Time since boot: 10 days 6:49 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment