Skip to content

Instantly share code, notes, and snippets.

@orisano

orisano/a.rb Secret

Last active July 25, 2024 08:31
Show Gist options
  • Save orisano/98792dee260106e9b6fcb45bbabeb1e6 to your computer and use it in GitHub Desktop.
Save orisano/98792dee260106e9b6fcb45bbabeb1e6 to your computer and use it in GitHub Desktop.
memory benchmarks
s = "foo "
require 'heap-profiler'
HeapProfiler.report('prof') do
1000000.times {
s.gsub(/ (\s+)/) { " #{' ' * Regexp.last_match(1).length}" }
}
end
ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [x86_64-linux]
---
Total allocated: 776.00 MB (9000002 objects)
Total retained: 584.00 B (5 objects)
allocated memory by gem
-----------------------------------
776.00 MB other
allocated memory by file
-----------------------------------
776.00 MB ../a.rb
allocated memory by location
-----------------------------------
776.00 MB ../a.rb:6
allocated memory by class
-----------------------------------
608.00 MB String
168.00 MB MatchData
40.00 B <svar> (IMEMO)
allocated objects by gem
-----------------------------------
9000002 other
allocated objects by file
-----------------------------------
9000002 ../a.rb
allocated objects by location
-----------------------------------
9000002 ../a.rb:6
allocated objects by class
-----------------------------------
8000000 String
1000001 MatchData
1 <svar> (IMEMO)
retained memory by gem
-----------------------------------
584.00 B other
retained memory by file
-----------------------------------
584.00 B ../a.rb
retained memory by location
-----------------------------------
584.00 B ../a.rb:6
retained memory by class
-----------------------------------
336.00 B Hash
168.00 B MatchData
40.00 B String
40.00 B <svar> (IMEMO)
retained objects by gem
-----------------------------------
5 other
retained objects by file
-----------------------------------
5 ../a.rb
retained objects by location
-----------------------------------
5 ../a.rb:6
retained objects by class
-----------------------------------
2 Hash
1 String
1 MatchData
1 <svar> (IMEMO)
Allocated String Report
-----------------------------------
80.00 MB 2000000 "foo "
2000000 ../a.rb:6
168.00 MB 1000000 "foo &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
1000000 ../a.rb:6
119.00 MB 1000000 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
1000000 ../a.rb:6
40.00 MB 1000000 "&nbsp;"
1000000 ../a.rb:6
121.00 MB 1000000 " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
1000000 ../a.rb:6
40.00 MB 1000000 " "
1000000 ../a.rb:6
40.00 MB 1000000 " "
1000000 ../a.rb:6
Retained String Report
-----------------------------------
40.00 B 1 "foo "
1 ../a.rb:6
ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-linux]
---
Total allocated: 1.13 GB (10000012 objects)
Total retained: 880.00 B (17 objects)
allocated memory by gem
-----------------------------------
1.13 GB other
320.00 B heap-profiler-0.7.0
allocated memory by file
-----------------------------------
1.13 GB ../a.rb
320.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb
allocated memory by location
-----------------------------------
1.13 GB ../a.rb:6
80.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:58
80.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:53
80.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:52
40.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:81
40.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:57
allocated memory by class
-----------------------------------
792.00 MB String
336.00 MB MatchData
240.00 B <callcache> (IMEMO)
200.00 B <constcache> (IMEMO)
40.00 B <svar> (IMEMO)
allocated objects by gem
-----------------------------------
10000004 other
8 heap-profiler-0.7.0
allocated objects by file
-----------------------------------
10000004 ../a.rb
8 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb
allocated objects by location
-----------------------------------
10000004 ../a.rb:6
2 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:58
2 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:53
2 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:52
1 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:81
1 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:57
allocated objects by class
-----------------------------------
8000000 String
2000000 MatchData
6 <callcache> (IMEMO)
5 <constcache> (IMEMO)
1 <svar> (IMEMO)
retained memory by gem
-----------------------------------
560.00 B other
320.00 B heap-profiler-0.7.0
retained memory by file
-----------------------------------
560.00 B ../a.rb
320.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb
retained memory by location
-----------------------------------
560.00 B ../a.rb:6
80.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:58
80.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:53
80.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:52
40.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:81
40.00 B heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:57
retained memory by class
-----------------------------------
280.00 B <callcache> (IMEMO)
240.00 B <constcache> (IMEMO)
168.00 B MatchData
80.00 B String
72.00 B Thread::Mutex
40.00 B <svar> (IMEMO)
retained objects by gem
-----------------------------------
9 other
8 heap-profiler-0.7.0
retained objects by file
-----------------------------------
9 ../a.rb
8 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb
retained objects by location
-----------------------------------
9 ../a.rb:6
2 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:58
2 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:53
2 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:52
1 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:81
1 heap-profiler-0.7.0/lib/heap_profiler/reporter.rb:57
retained objects by class
-----------------------------------
7 <callcache> (IMEMO)
6 <constcache> (IMEMO)
1 Thread::Mutex
1 String
1 MatchData
1 <svar> (IMEMO)
Allocated String Report
-----------------------------------
160.00 MB 2000000 "foo "
2000000 ../a.rb:6
192.00 MB 1000000 "foo &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
1000000 ../a.rb:6
160.00 MB 1000000 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
1000000 ../a.rb:6
40.00 MB 1000000 "&nbsp;"
1000000 ../a.rb:6
160.00 MB 1000000 " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
1000000 ../a.rb:6
40.00 MB 1000000 " "
1000000 ../a.rb:6
40.00 MB 1000000 " "
1000000 ../a.rb:6
Retained String Report
-----------------------------------
80.00 B 1 "foo "
1 ../a.rb:6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment