Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wuest committed Oct 3, 2024
1 parent 2957c65 commit 087a600
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
10 changes: 8 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
AllCops:
NewCops: enable

Layout/HashAlignment:
Enabled: false

Layout/MultilineHashBraceLayout:
Enabled: false

Layout/SpaceInsideParens:
Enabled: false

Expand Down Expand Up @@ -54,10 +60,10 @@ Style/GlobalVars:
Style/Lambda:
Enabled: false

Style/MultilineBlockChain:
Style/MixinUsage:
Enabled: false

Layout/MultilineHashBraceLayout:
Style/MultilineBlockChain:
Enabled: false

# != is business logic which must be tested
Expand Down
49 changes: 25 additions & 24 deletions example/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
#!/usr/bin/env ruby
$:.unshift(File.expand_path('../lib'))

# frozen_string_literal: true

$LOAD_PATH.unshift(File.expand_path('../lib'))
require 'simd'
require 'benchmark'

include SIMD

def sisd_loop(op, modulo, sisd, x)
sisd_loop = if modulo
if modulo
len = sisd.length
case op
when :*
->(e, i) { x << e * sisd[i % len] }
->(e, i) { x << (e * sisd[i % len]) }
when :+
->(e, i) { x << e + sisd[i % len] }
->(e, i) { x << (e + sisd[i % len]) }
when :/
->(e, i) { x << e / sisd[i % len] }
->(e, i) { x << (e / sisd[i % len]) }
when :-
->(e, i) { x << e - sisd[i % len] }
->(e, i) { x << (e - sisd[i % len]) }
end
else
case op
when :*
->(e, i) { x << e * sisd[i] }
->(e, i) { x << (e * sisd[i]) }
when :+
->(e, i) { x << e + sisd[i] }
->(e, i) { x << (e + sisd[i]) }
when :/
->(e, i) { x << e / sisd[i] }
->(e, i) { x << (e / sisd[i]) }
when :-
->(e, i) { x << e - sisd[i] }
->(e, i) { x << (e - sisd[i]) }
end
end
end
Expand All @@ -43,17 +46,15 @@ def sisd_loop(op, modulo, sisd, x)
s3 = FloatArray.new(a3)
s4 = FloatArray.new(a4)

modes = {
'Same size array' => [a2, [s1, s2]],
'4-wide operand' => [a3, [s1, s3]],
'2-wide operand' => [a4, [s1, s4]]
}
ops = {
'Multiplication' => :*,
'Addition' => :+,
'Division' => :/,
'Subtraction' => :-
}
modes = { 'Same size array' => [a2, [s1, s2]],
'4-wide operand' => [a3, [s1, s3]],
'2-wide operand' => [a4, [s1, s4]]
}
ops = { 'Multiplication' => :*,
'Addition' => :+,
'Division' => :/,
'Subtraction' => :-
}

modes.each do |mode, args|
puts " *** #{mode} ***"
Expand All @@ -65,17 +66,17 @@ def sisd_loop(op, modulo, sisd, x)

Benchmark.bm do |b|
b.report('SIMD') { iter.times { s1.method(op).call(s2) } }
b.report('SISD') do
b.report('Ruby') do
iter.times do
a1.each_with_index(&(sisd_loop(op, modulo, sisd, Array.new)))
a1.each_with_index(&sisd_loop(op, modulo, sisd, []))
end
end
end
end
puts
end

puts " *** Square root calculation *** "
puts ' *** Square root calculation *** '
Benchmark.bm do |b|
b.report('SIMD') { iter.times { s1.sqrt } }
b.report('SISD') do
Expand Down

0 comments on commit 087a600

Please sign in to comment.