-
Notifications
You must be signed in to change notification settings - Fork 35
/
Rakefile
93 lines (76 loc) · 2.11 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "json"
require "terminal-table"
require "rake/extensiontask"
require "pty"
require "rubocop/rake_task"
gem = Gem::Specification.load(File.dirname(__FILE__) + "/panko_serializer.gemspec")
Rake::ExtensionTask.new("panko_serializer", gem) do |ext|
ext.lib_dir = "lib/panko"
end
Gem::PackageTask.new(gem) do |pkg|
pkg.need_zip = pkg.need_tar = false
end
RSpec::Core::RakeTask.new(:spec)
Rake::Task[:spec].prerequisites << :compile
Rake::Task[:compile].prerequisites << :clean
task default: :spec
RuboCop::RakeTask.new
def print_and_flush(str)
print str
$stdout.flush
end
def run_process(cmd)
puts "> Running #{cmd}"
lines = []
_stderr_reader, stderr_writer = IO.pipe
PTY.spawn(cmd, err: stderr_writer.fileno) do |stdout, stdin, pid|
stdout.each do |line|
print_and_flush "."
lines << line
end
rescue Errno::EIO
# ignore this
end
lines
rescue PTY::ChildExited
puts "The child process exited! - #{cmd}"
[]
end
def run_benchmarks(files, items_count: 2_300)
headings = ["Benchmark", "ip/s", "allocs/retained"]
files.each do |benchmark_file|
lines = run_process "ITEMS_COUNT=#{items_count} RAILS_ENV=production ruby #{benchmark_file}"
rows = lines.map do |line|
row = JSON.parse(line)
row.values
rescue JSON::ParserError
puts "> [ERROR] Failed running #{benchmark_file} - #{lines.join}"
end
puts "\n\n"
title = File.basename(benchmark_file, ".rb")
table = Terminal::Table.new title: title, headings: headings, rows: rows
puts table
end
end
namespace :benchmarks do
desc "All"
task :all do
run_benchmarks Dir[File.join(__dir__, "benchmarks", "**", "bm_*")]
end
desc "Type Casts"
task :type_casts do
run_benchmarks Dir[File.join(__dir__, "benchmarks", "type_casts", "bm_*")], items_count: 0
end
desc "Sanity"
task :sanity do
puts Time.now.strftime("%d/%m %H:%M:%S")
puts "=========================="
run_benchmarks [
File.join(__dir__, "benchmarks", "sanity.rb")
], items_count: 2300
puts "\n\n"
end
end