apple / swift-collections-benchmark

A benchmarking tool for Swift Collection algorithms
Apache License 2.0
340 stars 23 forks source link

Example code crashes on linux #12

Open Trzyipolkostkicukru opened 3 years ago

Trzyipolkostkicukru commented 3 years ago

Example code from README.md crashes on linux. The message I'm getting after installing swift-backtrace is "Swift runtime failure: Double value cannot be converted to Int because it is either infinite or NaN"

Project files without the ".build" directory ThisIsBenchmark.zip (if I included .build it would be too big for github)

Information

Checklist

Steps to Reproduce

Replace this paragraph with an explanation of how to reproduce the incorrect behavior. Include a simple code example, if possible.

Running 2 tasks on 76 sizes from 1 to 1M:
  Array<Int> sorted
  Set<Int> contains
Output file: /home/cukier/Desktop/ThisIsBenchmark/out
Appending to existing data (if any) for these tasks/sizes.

Collecting data:
  10x7f3f4a3653bf
0x55b70ba8f75d, Swift runtime failure: Double value cannot be converted to Int because it is either infinite or NaN at /home/cukier/Desktop/ThisIsBenchmark/.build/checkouts/swift-collections-benchmark/Sources/CollectionsBenchmark/Benchmark/Task.swift:0
0x55b70ba8f75d, CollectionsBenchmark.Task.measure(size: CollectionsBenchmark.Size, input: A, options: CollectionsBenchmark.Benchmark.Options) -> Swift.Optional<CollectionsBenchmark.Time> at /home/cukier/Desktop/ThisIsBenchmark/.build/checkouts/swift-collections-benchmark/Sources/CollectionsBenchmark/Benchmark/Task.swift:121
0x55b70ba60956, CollectionsBenchmark._ConcreteTask.measure(size: CollectionsBenchmark.Size, input: Any, options: CollectionsBenchmark.Benchmark.Options) -> Swift.Optional<CollectionsBenchmark.Time> at /home/cukier/Desktop/ThisIsBenchmark/.build/checkouts/swift-collections-benchmark/Sources/CollectionsBenchmark/Benchmark/AnyTask.swift:119
0x55b70ba78101, CollectionsBenchmark.AnyTask.measure(size: CollectionsBenchmark.Size, input: Any, options: CollectionsBenchmark.Benchmark.Options) -> Swift.Optional<CollectionsBenchmark.Time> at .build/checkouts/swift-collections-benchmark/Sources/CollectionsBenchmark/Benchmark/AnyTask.swift:49
0x55b70ba78101, function signature specialization <Arg[3] = [Closure Propagated : closure #2 (CollectionsBenchmark.Benchmark.Event) throws -> () in CollectionsBenchmark._Document.run(benchmark: CollectionsBenchmark.Benchmark, options: CollectionsBenchmark.Benchmark.Options) throws -> (), Argument Types : [Swift.BoolCollectionsBenchmark._Document]> of CollectionsBenchmark.Benchmark.measureOneCycle(tasks: Swift.Array<CollectionsBenchmark.AnyTask>, sizes: Swift.Array<CollectionsBenchmark.Size>, options: CollectionsBenchmark.Benchmark.Options, delegate: (CollectionsBenchmark.Benchmark.Event) throws -> ()) throws -> () at /home/cukier/Desktop/ThisIsBenchmark/.build/checkouts/swift-collections-benchmark/Sources/CollectionsBenchmark/Benchmark/Benchmark+RunOptions.swift:40
0x55b70ba7963d, function signature specialization <Arg[1] = [Closure Propagated : closure #2 (CollectionsBenchmark.Benchmark.Event) throws -> () in CollectionsBenchmark._Document.run(benchmark: CollectionsBenchmark.Benchmark, options: CollectionsBenchmark.Benchmark.Options) throws -> (), Argument Types : [Swift.BoolCollectionsBenchmark._Document]> of CollectionsBenchmark.Benchmark.run(options: CollectionsBenchmark.Benchmark.Options, delegate: (CollectionsBenchmark.Benchmark.Event) throws -> ()) throws -> () at /home/cukier/Desktop/ThisIsBenchmark/.build/checkouts/swift-collections-benchmark/Sources/CollectionsBenchmark/Benchmark/Benchmark+RunOptions.swift:73
0x55b70bae0a41, CollectionsBenchmark._Document.run(benchmark: CollectionsBenchmark.Benchmark, options: CollectionsBenchmark.Benchmark.Options) throws -> () at /home/cukier/Desktop/ThisIsBenchmark/.build/checkouts/swift-collections-benchmark/Sources/CollectionsBenchmark/BenchmarkCLI/_Document.swift:149
0x55b70badb00b, CollectionsBenchmark._BenchmarkCLI.Run.run(benchmark: CollectionsBenchmark.Benchmark) throws -> () at /home/cukier/Desktop/ThisIsBenchmark/.build/checkouts/swift-collections-benchmark/Sources/CollectionsBenchmark/BenchmarkCLI/BenchmarkCLI+Run.swift:76
0x55b70badb23f, protocol witness for CollectionsBenchmark._BenchmarkCommand.run(benchmark: CollectionsBenchmark.Benchmark) throws -> () in conformance CollectionsBenchmark._BenchmarkCLI.Run : CollectionsBenchmark._BenchmarkCommand in CollectionsBenchmark at /home/cukier/Desktop/ThisIsBenchmark/<compiler-generated>:0
0x55b70ba6a9fc, CollectionsBenchmark.Benchmark.main() -> () at /home/cukier/Desktop/ThisIsBenchmark/.build/checkouts/swift-collections-benchmark/Sources/CollectionsBenchmark/Benchmark/Benchmark+Main.swift:32
0x55b70bb316f2, ThisIsBenchmark_main at /home/cukier/Desktop/ThisIsBenchmark/Sources/ThisIsBenchmark/main.swift:27
0x7f3f498d60b2
0x55b70b9da6dd
0xffffffffffffffff
Illegal instruction (core dumped)
lorentey commented 8 months ago

Also reproduced on macOS: https://github.com/apple/swift-collections/issues/345#issuecomment-1925098634

This can happen when the average duration measured happens to be zero. The fix ought to be straightforward.