diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3fff58e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main, next ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Swift + uses: swift-actions/setup-swift@v2 + with: + swift-version: "6.1" + + - name: Swift version + run: swift --version + + - name: Build + run: swift build + + - name: Run tests + run: | + if [ -d Tests ]; then + swift test --parallel + fi \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8818591..6fb1634 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .DS_Store /.build /Packages +/Benchmarks/.build +/Benchmarks/Packages xcuserdata/ DerivedData/ .swiftpm/configuration/registries.json diff --git a/Benchmarks/.build/index-build/arm64-apple-macosx/debug/index/db/v13/p82701--ae223f/data.mdb b/Benchmarks/.build/index-build/arm64-apple-macosx/debug/index/db/v13/p82701--ae223f/data.mdb new file mode 100644 index 0000000..aa89ad8 Binary files /dev/null and b/Benchmarks/.build/index-build/arm64-apple-macosx/debug/index/db/v13/p82701--ae223f/data.mdb differ diff --git a/Benchmarks/.build/index-build/arm64-apple-macosx/debug/index/db/v13/p82701--ae223f/lock.mdb b/Benchmarks/.build/index-build/arm64-apple-macosx/debug/index/db/v13/p82701--ae223f/lock.mdb new file mode 100644 index 0000000..a1d616a Binary files /dev/null and b/Benchmarks/.build/index-build/arm64-apple-macosx/debug/index/db/v13/p82701--ae223f/lock.mdb differ diff --git a/Package.resolved b/Benchmarks/Package.resolved similarity index 92% rename from Package.resolved rename to Benchmarks/Package.resolved index ea4eb4e..7f13fd1 100644 --- a/Package.resolved +++ b/Benchmarks/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "3f9074c07e2e5a40ea00949c3aeee3ea2b7f18c10b45da8961e3c52eb57a8b26", + "originHash" : "505b7993e954282da13a8ea56f4457f288b4e59461fba552d69d57a150a5c844", "pins" : [ { "identity" : "hdrhistogram-swift", @@ -42,8 +42,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-atomics.git", "state" : { - "revision" : "cd142fd2f64be2100422d658e7411e39489da985", - "version" : "1.2.0" + "revision" : "b601256eab081c0f92f059e12818ac1d4f178ff7", + "version" : "1.3.0" } }, { diff --git a/Benchmarks/Package.swift b/Benchmarks/Package.swift new file mode 100644 index 0000000..ddb43ea --- /dev/null +++ b/Benchmarks/Package.swift @@ -0,0 +1,32 @@ +// swift-tools-version: 6.1 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +// swift-tools-version: 6.1 + +import PackageDescription + +let package = Package( + name: "benchmarks", + platforms: [ + .macOS(.v13), + .iOS(.v16) + ], + dependencies: [ + .package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.29.3"), + .package(path: "../") + ], + targets: [ + .executableTarget( + name: "HyperLogLogBenchmarks", + dependencies: [ + .product(name: "Benchmark", package: "package-benchmark"), + .product(name: "HyperLogLog", package: "swift-hyperloglog"), + ], + path: "HyperLogLogBenchmarks/", + plugins: [ + .plugin(name: "BenchmarkPlugin", package: "package-benchmark") + ] + ), + ] +) + diff --git a/Package.swift b/Package.swift index 706c0f8..eb1bc16 100644 --- a/Package.swift +++ b/Package.swift @@ -5,19 +5,12 @@ import PackageDescription let package = Package( name: "swift-hyperloglog", - platforms: [ - .macOS(.v13), - .iOS(.v16) - ], products: [ // Products define the executables and libraries a package produces, making them visible to other packages. .library( name: "HyperLogLog", targets: ["HyperLogLog"]), ], - dependencies: [ - .package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.29.3"), - ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. // Targets can depend on other targets in this package and products from dependencies. @@ -28,19 +21,4 @@ let package = Package( dependencies: ["HyperLogLog"] ), ] -) - -// Benchmark of HyperLogLogBenchmarks -package.targets += [ - .executableTarget( - name: "HyperLogLogBenchmarks", - dependencies: [ - .product(name: "Benchmark", package: "package-benchmark"), - "HyperLogLog", - ], - path: "Benchmarks/HyperLogLogBenchmarks", - plugins: [ - .plugin(name: "BenchmarkPlugin", package: "package-benchmark") - ] - ), -] \ No newline at end of file +) \ No newline at end of file diff --git a/Sources/HyperLogLog/HyperLogLog.swift b/Sources/HyperLogLog/HyperLogLog.swift index d262206..c148fed 100644 --- a/Sources/HyperLogLog/HyperLogLog.swift +++ b/Sources/HyperLogLog/HyperLogLog.swift @@ -4,6 +4,8 @@ import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(WASILibc) + import WASILibc #endif /// A protocol for hashing values. diff --git a/Tests/HyperLogLogTests/HyperLogLogTests.swift b/Tests/HyperLogLogTests/HyperLogLogTests.swift index be6afb0..828c8bc 100644 --- a/Tests/HyperLogLogTests/HyperLogLogTests.swift +++ b/Tests/HyperLogLogTests/HyperLogLogTests.swift @@ -9,7 +9,7 @@ import Testing #endif @Test func example() async throws { - var hll = HyperLogLog(precision: 10) + var hll = HyperLogLog(precision: .highest) hll.insert("a") hll.insert("b") hll.insert("c") @@ -21,7 +21,7 @@ import Testing } @Test func example2() async throws { - var hll = HyperLogLog(precision: 10) + var hll = HyperLogLog(precision: .highest) hll.insert("a") hll.insert("b") hll.insert("b")