Skip to content

Commit ca35c75

Browse files
Create benchmark workflow
Run a benchmark as part of our CI to ensure new code does not degrade performance.
1 parent f7a8e72 commit ca35c75

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

.github/workflows/bench.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Bench
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
name: Benchmarks
13+
steps:
14+
- uses: actions/checkout@v6
15+
- uses: ruby/setup-ruby@v1
16+
with:
17+
ruby-version: '3.4'
18+
- name: Install dependencies
19+
run: bundle install
20+
21+
- name: Generators
22+
run: RUBYOPT="-W0" bundle exec ruby benchmark/generators.rb
23+
- name: Require
24+
run: RUBYOPT="-W0" bundle exec ruby benchmark/load.rb

benchmark/load.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
# frozen_string_literal: true
22

3-
require 'benchmark/ips'
4-
require 'benchmark'
3+
require "benchmark"
54

6-
if defined?(Faker)
7-
raise 'faker is defined before bench'
8-
end
5+
ms = Benchmark.realtime do
6+
require 'faker'
7+
end * 1000
98

10-
path = File.expand_path("#{File.dirname(__FILE__)}/load_faker.rb")
11-
12-
Benchmark.ips do |x|
13-
x.report('Loading Time') do
14-
system("ruby #{path}")
15-
end
16-
end
9+
puts "took #{ms}ms to laod"

benchmark/load_faker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
if defined?(Faker)
4-
raise 'faker is already defined...'
4+
raise 'faker is defined before load'
55
end
66

77
load(File.expand_path("#{File.dirname(__FILE__)}/../lib/faker.rb"))

0 commit comments

Comments
 (0)