Skip to content

Commit

Permalink
Merge branch 'eregon-github-actions'
Browse files Browse the repository at this point in the history
  • Loading branch information
larskanis committed Mar 30, 2020
2 parents b89831d + caf6417 commit 4a5cf10
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,38 @@
name: CI
on: [push, pull_request]
jobs:
specs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu, macos, windows ]
ruby: [ 2.3, 2.4, 2.5, 2.6, 2.7, ruby-head, truffleruby-head ]
exclude:
- os: windows
ruby: truffleruby-head
- os: windows
ruby: 2.3 # compilation fails
runs-on: ${{ matrix.os }}-latest
env:
MAKE: "make" # to not try to use gmake on Windows
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}

- run: brew install automake
if: matrix.os == 'macos'

# Bundler 2 seems to fix installing rubygems-tasks on Ruby < 2.4
- run: gem install bundler
- run: bundle install
- run: bundle exec rake libffi
- run: bundle exec rake compile

- run: bundle exec rake test

- run: bundle exec rake bench:all
if: matrix.ruby != 'truffleruby-head'
env:
ITER: 10
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -45,7 +45,7 @@ task :test => [ :spec ]

namespace :bench do
ITER = ENV['ITER'] ? ENV['ITER'].to_i : 100000
bench_files = Dir["bench/bench_*.rb"].reject { |f| f == "bench/bench_helper.rb" }
bench_files = Dir["bench/bench_*.rb"].sort.reject { |f| f == "bench/bench_helper.rb" }
bench_files.each do |bench|
task File.basename(bench, ".rb")[6..-1] => :compile do
sh %{#{Gem.ruby} #{bench} #{ITER}}
Expand Down
10 changes: 7 additions & 3 deletions bench/bench_getlogin.rb
Expand Up @@ -9,8 +9,12 @@ module Posix
ffi_lib FFI::Library::LIBC
attach_function :getlogin, [], :string
end
if Posix.getlogin != Etc.getlogin
raise ArgumentError, "FFI getlogin returned incorrect value"

# getlogin(2) might return NULL, in which case Etc.getlogin uses ENV["USER"].
# This should not matter for this benchmark, getlogin() is still called.
if (Posix.getlogin || ENV["USER"]) != Etc.getlogin
raise ArgumentError, "FFI getlogin returned incorrect value: " \
"#{Posix.getlogin.inspect} (FFI) vs #{Etc.getlogin.inspect} (Etc)"
end

puts "Benchmark FFI getlogin(2) performance, #{ITER}x"
Expand All @@ -27,4 +31,4 @@ module Posix
iter.times { Etc.getlogin }
}
}
end
end unless FFI::Platform.windows?
2 changes: 1 addition & 1 deletion bench/bench_gettimeofday.rb
Expand Up @@ -50,4 +50,4 @@ class Timeval < FFI::Struct
iter.times { Time.now }
}
}
end
end unless FFI::Platform.windows?
2 changes: 1 addition & 1 deletion bench/bench_getuid.rb
Expand Up @@ -24,4 +24,4 @@ module Posix
iter.times { Process.uid }
}
}
end
end unless FFI::Platform.windows?
2 changes: 1 addition & 1 deletion bench/bench_math.rb
Expand Up @@ -3,7 +3,7 @@
module BenchMath
module FFIMath
extend FFI::Library
ffi_lib 'm'
ffi_lib FFI::Platform.windows? ? FFI::Library::LIBC : 'm'
attach_function :cos, [ :double ], :double
attach_function :cosf, [ :float ], :float
end
Expand Down
2 changes: 1 addition & 1 deletion bench/bench_umask.rb
Expand Up @@ -59,4 +59,4 @@ def self.umask(mask = nil)
ITER.times { NativeFile.umask }
}
}
end
end unless FFI::Platform.windows?

0 comments on commit 4a5cf10

Please sign in to comment.