summaryrefslogtreecommitdiff
path: root/lib/vendor/excon/benchmarks/for_vs_hash_each.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vendor/excon/benchmarks/for_vs_hash_each.rb')
-rw-r--r--lib/vendor/excon/benchmarks/for_vs_hash_each.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/vendor/excon/benchmarks/for_vs_hash_each.rb b/lib/vendor/excon/benchmarks/for_vs_hash_each.rb
new file mode 100644
index 0000000..c4db5ef
--- /dev/null
+++ b/lib/vendor/excon/benchmarks/for_vs_hash_each.rb
@@ -0,0 +1,27 @@
+require 'rubygems'
+require 'tach'
+
+data = {"some" => "var", "goes" => "in", :here => 0}
+Tach.meter(1_000_000) do
+ tach('for') do
+ for key, values in data
+ key == values
+ end
+ end
+ tach('each') do
+ data.each do |key, values|
+ key == values
+ end
+ end
+end
+
+# ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
+#
+# +------+----------+
+# | tach | total |
+# +------+----------+
+# | each | 2.748909 |
+# +------+----------+
+# | for | 2.949512 |
+# +------+----------+
+#