Skip to content

Commit 8d9e752

Browse files
avellableJuanitoFatas
authored andcommitted
Add example for immutable vs mutable strings
1 parent d6e1ac0 commit 8d9e752

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'benchmark/ips'
2+
3+
IMMUTABLE_TEST = "writing_fast_ruby".freeze
4+
mutable_test = "writing_fast_ruby"
5+
6+
hash = {"writing_fast_ruby" => "is_cool"}
7+
8+
Benchmark.ips do |x|
9+
x.report("freeze") { hash[IMMUTABLE_TEST] }
10+
x.report("normal") { hash[mutable_test] }
11+
x.compare!
12+
end

0 commit comments

Comments
 (0)