-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ee5e138
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Ignore OSX dir files | ||
.DS_Store | ||
|
||
# Ignore Vim swap files | ||
*.swp | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/ruby | ||
|
||
require 'benchmark' | ||
|
||
no_gc = ARGV[0] == '-o' | ||
|
||
num_rows = 100_000 | ||
num_cols = 10 | ||
|
||
data = Array.new(num_rows) do | ||
Array.new(num_cols) { 'x' * 1000 } | ||
end | ||
|
||
mem_before = "%d MB" % (`ps -o rss= -p #{Process.pid}`.to_i / 1024) | ||
|
||
GC.disable if no_gc | ||
time = Benchmark.realtime do | ||
csv = data.map do |row| | ||
row.join(',') | ||
end.join("\n") | ||
end | ||
|
||
mem_after = "%d MB" % (`ps -o rss= -p #{Process.pid}`.to_i / 1024) | ||
|
||
puts "Time: #{time} (GC #{no_gc ? 'disabled' : 'enabled'})" | ||
puts "MEM: #{mem_before} -> #{mem_after}" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/ruby | ||
|
||
require 'benchmark' | ||
|
||
num_rows = 100_000 | ||
num_cols = 10 | ||
|
||
data = Array.new(num_rows) do | ||
Array.new(num_cols) { 'x' * 1000 } | ||
end | ||
|
||
mem_before = "%d MB" % (`ps -o rss= -p #{Process.pid}`.to_i / 1024) | ||
|
||
time = Benchmark.realtime do | ||
csv = '' | ||
num_rows.times do |i| | ||
num_cols.times do |j| | ||
csv << data[i][j] | ||
csv << ',' unless j == num_cols - 1 | ||
end | ||
|
||
csv << "\n" unless i == num_rows - 1 | ||
end | ||
end | ||
|
||
mem_after = "%d MB" % (`ps -o rss= -p #{Process.pid}`.to_i / 1024) | ||
|
||
puts "Time: #{time}" | ||
puts "MEM: #{mem_before} -> #{mem_after}" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Ruby Performance Optimization Book Examples | ||
|
||
## Try to disable GC and define memory consumption | ||
|
||
1. GC often makes Ruby slow (especialy <= v2.0 ). And that's because of high memory consumption | ||
2. Ruby has significant memory overhead | ||
3. GC in v2.1+ is 5 times faster! | ||
4. Raw performance of v1.9 - v2.3 is about the same | ||
|
||
See [001_gc.rb]. | ||
|
||
## Try to optimize memory | ||
|
||
1. 80% of performance optimization comes from memory optimization | ||
|
||
See [002_memory.rb] | ||
|