//===--- FloatingPointPrinting.swift -----------------------------------===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2018 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // //===----------------------------------------------------------------------===// // This test verifies the performance of generating a text description // from a binary floating-point value. import TestsUtils public let benchmarks = [ BenchmarkInfo( name: "FloatingPointPrinting_Float_description_small", runFunction: run_FloatingPointPrinting_Float_description_small, tags: [.validation, .api, .runtime, .String], legacyFactor: 108), BenchmarkInfo( name: "FloatingPointPrinting_Double_description_small", runFunction: run_FloatingPointPrinting_Double_description_small, tags: [.validation, .api, .runtime, .String], legacyFactor: 100), BenchmarkInfo( name: "FloatingPointPrinting_Float80_description_small", runFunction: run_FloatingPointPrinting_Float80_description_small, tags: [.validation, .api, .runtime, .String], legacyFactor: 108), BenchmarkInfo( name: "FloatingPointPrinting_Float_description_uniform", runFunction: run_FloatingPointPrinting_Float_description_uniform, tags: [.validation, .api, .runtime, .String], legacyFactor: 100), BenchmarkInfo( name: "FloatingPointPrinting_Double_description_uniform", runFunction: run_FloatingPointPrinting_Double_description_uniform, tags: [.validation, .api, .runtime, .String], legacyFactor: 100), BenchmarkInfo( name: "FloatingPointPrinting_Float80_description_uniform", runFunction: run_FloatingPointPrinting_Float80_description_uniform, tags: [.validation, .api, .runtime, .String], legacyFactor: 100), BenchmarkInfo( name: "FloatingPointPrinting_Float_interpolated", runFunction: run_FloatingPointPrinting_Float_interpolated, tags: [.validation, .api, .runtime, .String], legacyFactor: 200), BenchmarkInfo( name: "FloatingPointPrinting_Double_interpolated", runFunction: run_FloatingPointPrinting_Double_interpolated, tags: [.validation, .api, .runtime, .String], legacyFactor: 200), BenchmarkInfo( name: "FloatingPointPrinting_Float80_interpolated", runFunction: run_FloatingPointPrinting_Float80_interpolated, tags: [.validation, .api, .runtime, .String], legacyFactor: 200) ] // Generate descriptions for 100,000 values around 1.0. // // Note that some formatting algorithms behave very // differently for values around 1.0 than they do for // less-common extreme values. Having a "small" test // and a "uniform" test exercises both cases. // // Dividing integers 1...100000 by 101 (a prime) yields floating-point // values from about 1e-2 to about 1e3, each with plenty of digits after // the decimal: @inline(never) public func run_FloatingPointPrinting_Float_description_small(_ n: Int) { let count = 1_000 for _ in 0..