Registry Mirror
搜索
Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Files
Expand file tree
main
Breadcrumbs
fast-ruby
/
code
/
string
/
mutable_vs_immutable_strings.rb
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
17 lines (14 loc) · 309 Bytes
main
Breadcrumbs
fast-ruby
/
code
/
string
/
mutable_vs_immutable_strings.rb
Copy path
Top
File metadata and controls
Code
Blame
17 lines (14 loc) · 309 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require "benchmark/ips"
# Keeps and reuses shared string
def fast
"To freeze or not to freeze".freeze
end
# Allocates new string over and over again
def slow
"To freeze or not to freeze"
end
Benchmark.ips do |x|
x.report("With Freeze") { fast }
x.report("Without Freeze") { slow }
x.compare!
end
You can’t perform that action at this time.