mirror of https://github.com/sbt/sbt.git
Add file benchmark
This commit is contained in:
parent
07efae45a6
commit
cddb496180
|
|
@ -56,6 +56,10 @@ jobs:
|
|||
java: 17
|
||||
distribution: zulu
|
||||
jobtype: 12
|
||||
- os: ubuntu-latest
|
||||
java: 17
|
||||
distribution: temurin
|
||||
jobtype: 13
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: 25
|
||||
env:
|
||||
|
|
@ -202,4 +206,9 @@ jobs:
|
|||
if: ${{ matrix.jobtype == 12 }}
|
||||
shell: bash
|
||||
run: |
|
||||
./sbt -v "scripted cache/*"
|
||||
./sbt -v "scripted cache/*"
|
||||
- name: Hash Benchmark
|
||||
if: ${{ matrix.jobtype == 13 }}
|
||||
shell: bash
|
||||
run: |
|
||||
./sbt -v "hashBenchmark/Jmh/run -i 5 -wi 3 -f1 -t1"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
package sbt.internal.util
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
import org.openjdk.jmh.annotations.*
|
||||
import sbt.util.Digest
|
||||
|
||||
import java.nio.file.{ Path as NioPath }
|
||||
import sbt.io.IO
|
||||
import sbt.io.syntax.*
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
abstract class AbstractFileHashBenchmark:
|
||||
val tempDir = IO.createTemporaryDirectory
|
||||
val temp = tempDir / "test.txt"
|
||||
val buf: Array[Byte] = Array.fill[Byte](1024)(0.toByte)
|
||||
for i <- 0 until 1024 do IO.append(temp, buf)
|
||||
|
||||
def hash(path: NioPath): String
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Array(Mode.AverageTime))
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
def hashFile: Unit =
|
||||
hash(temp.toPath())
|
||||
end AbstractFileHashBenchmark
|
||||
|
||||
class XXHash64FileHashBenchmark extends AbstractFileHashBenchmark:
|
||||
override def hash(path: NioPath): String =
|
||||
Digest.xx64Hash(path).toString
|
||||
|
||||
class WyHash64FileHashBenchmark extends AbstractFileHashBenchmark:
|
||||
override def hash(path: NioPath): String =
|
||||
Digest.wy64Hash(path).toString
|
||||
|
||||
class ImoXXHash64FileHashBenchmark extends AbstractFileHashBenchmark:
|
||||
override def hash(path: NioPath): String =
|
||||
Digest.imoxx64Hash(path).toString
|
||||
|
||||
class ImoWyHash64FileHashBenchmark extends AbstractFileHashBenchmark:
|
||||
override def hash(path: NioPath): String =
|
||||
Digest.imowy64Hash(path).toString
|
||||
|
||||
class Sha1FileHashBenchmark extends AbstractFileHashBenchmark:
|
||||
override def hash(path: NioPath): String =
|
||||
Digest.sha1Hash(path).toString
|
||||
|
||||
class Sha256FileHashBenchmark extends AbstractFileHashBenchmark:
|
||||
override def hash(path: NioPath): String =
|
||||
Digest.sha256Hash(path).toString
|
||||
|
|
@ -75,6 +75,9 @@ object Digest:
|
|||
|
||||
lazy val zero: Digest = dummy(0L)
|
||||
|
||||
private[sbt] def sha1Hash(path: Path): Digest =
|
||||
apply(Sha1, path)
|
||||
|
||||
def sha256Hash(path: Path): Digest = apply(Sha256, path)
|
||||
|
||||
def sha256Hash(bytes: Array[Byte]): Digest =
|
||||
|
|
|
|||
Loading…
Reference in New Issue