|
| 1 | +//===--- FloatingPointConversion.swift ------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +import TestsUtils |
| 14 | + |
| 15 | +public let FloatingPointConversion = [ |
| 16 | + BenchmarkInfo( |
| 17 | + name: "ConvertFloatingPoint.ConcreteDoubleToDouble", |
| 18 | + runFunction: run_ConvertFloatingPoint_ConcreteDoubleToDouble, |
| 19 | + tags: [.validation, .api]), |
| 20 | + BenchmarkInfo( |
| 21 | + name: "ConvertFloatingPoint.GenericDoubleToDouble", |
| 22 | + runFunction: run_ConvertFloatingPoint_GenericDoubleToDouble, |
| 23 | + tags: [.validation, .api]), |
| 24 | +] |
| 25 | + |
| 26 | +let doubles = [ |
| 27 | + 1.8547832857295, 26.321549267719135, 98.9544480962058, 73.70286973782363, |
| 28 | + 82.04918555938816, 76.38902969312758, 46.35647857011161, 64.0821426030317, |
| 29 | + 97.82373347320156, 55.742361037720634, 23.677941665488856, 93.7347588108058, |
| 30 | + 80.72657040828412, 32.137580733275826, 64.78192587530002, 21.459686568896863, |
| 31 | + 24.88407660280718, 85.25905561999171, 12.858847331083556, 29.418845887252864, |
| 32 | + 67.64627066438761, 68.09883494078815, 57.781587230862094, 63.38335631088038, |
| 33 | + 83.31376661495327, 87.45936846358906, 0.6757674136841918, 86.45465036820696, |
| 34 | + 84.72715137492781, 82.67894289189142, 26.1667640621554, 21.24895661442493, |
| 35 | + 65.06399183516027, 90.06549073883058, 59.2736650501005, 94.5800380563246, |
| 36 | + 84.22617424003917, 26.93158630395639, 9.069952095976841, 96.10067836567679, |
| 37 | + 62.60505762081415, 29.57878462599286, 66.06040114311294, 51.709999429326636, |
| 38 | + 64.79777579583545, 45.25948795832151, 94.31492354198335, 52.31096166433902, |
| 39 | +] |
| 40 | + |
| 41 | +@inline(__always) |
| 42 | +func convert< |
| 43 | + T: BinaryFloatingPoint, U: BinaryFloatingPoint |
| 44 | +>(_ value: T, to: U.Type) -> U { |
| 45 | + U(value) |
| 46 | +} |
| 47 | + |
| 48 | +@inline(never) |
| 49 | +public func run_ConvertFloatingPoint_ConcreteDoubleToDouble(_ N: Int) { |
| 50 | + for _ in 0..<(N * 100) { |
| 51 | + for element in doubles { |
| 52 | + let f = Double(identity(element)) |
| 53 | + blackHole(f) |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +@inline(never) |
| 59 | +public func run_ConvertFloatingPoint_GenericDoubleToDouble(_ N: Int) { |
| 60 | + for _ in 0..<(N * 100) { |
| 61 | + for element in doubles { |
| 62 | + let f = convert(identity(element), to: Double.self) |
| 63 | + blackHole(f) |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments