Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Quafadas committed Sep 25, 2024
1 parent 5f330f6 commit 547400c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
8 changes: 4 additions & 4 deletions benchmark/src/vectorAddition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ class AddScalarBenchmark extends BLASBenchmark:

@Benchmark
def vecxt_add(bh: Blackhole) =
val add1 = vec.scalarPlus(4.5)
bh.consume(add1);
vec.scalarPlus(4.5)
bh.consume(vec);
end vecxt_add

@Benchmark
def vecxt_add_vec(bh: Blackhole) =
val add1 = vec2 +:+= 4.5
bh.consume(add1);
vec2 +:+= 4.5
bh.consume(vec2);
end vecxt_add_vec
end AddScalarBenchmark

2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ benchmark:
mill benchmark.runJmh -jvmArgs --add-modules=jdk.incubator.vector -rf json

benchmarkOnly:
mill benchmark.runJmh -jvmArgs --add-modules=jdk.incubator.vector -rf json vecxt.benchmark.IncrementBenchmark
mill benchmark.runJmh -jvmArgs --add-modules=jdk.incubator.vector -rf json vecxt.benchmark.AddScalarBenchmark
1 change: 1 addition & 0 deletions site/docs/_assets/plots/addScalar.vg.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",

"data": {
"url": "../../benchmarks/benchmark_history.json",
"format": {
Expand Down
16 changes: 14 additions & 2 deletions vecxt/jvm/src/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,21 @@ object extensions:
end extension
extension (vec: Array[Boolean])
inline def countTrue: Int =
val species = VectorSpecies.ofBoolean(VectorSpecies.PREFERRED)
val length = species.length()
var sum = 0
for i <- 0 until vec.length do if vec(i) then sum = sum + 1
end for
var i = 0

while i < species.loopBound(vec.length) do
sum += DoubleVector.fromArray(species, vec, i).compare(VectorOperators.EQ, true).trueCount
i += length
end while

while i < vec.length do
if vec(i) then
sum += 1
i += 1
end while
sum
end countTrue

Expand Down

0 comments on commit 547400c

Please sign in to comment.