//===--- FloatingPointParsing.swift -----------------------------------===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2019 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 parsing a floating point value // from a String. import TestsUtils public let benchmarks = [ BenchmarkInfo( name: "ParseFloat.Float.Exp", runFunction: run_ParseFloatExp, tags: [.validation, .api, .runtime, .String]), BenchmarkInfo( name: "ParseFloat.Double.Exp", runFunction: run_ParseDoubleExp, tags: [.validation, .api, .runtime, .String]), BenchmarkInfo( name: "ParseFloat.Float80.Exp", runFunction: run_ParseFloat80Exp, tags: [.validation, .api, .runtime, .String]), BenchmarkInfo( name: "ParseFloat.Float.Uniform", runFunction: run_ParseFloatUniform, tags: [.validation, .api, .runtime, .String]), BenchmarkInfo( name: "ParseFloat.Double.Uniform", runFunction: run_ParseDoubleUniform, tags: [.validation, .api, .runtime, .String]), BenchmarkInfo( name: "ParseFloat.Float80.Uniform", runFunction: run_ParseFloat80Uniform, tags: [.validation, .api, .runtime, .String]), ] /// The 'Exp' test: /// Generates values following a truncated exponential distribution on 0...1000, /// each rounded to a number of significant digits uniformly selected from /// 1...6 (Float), 1...15 (Double) and 1...18 (Float80). /// This is a good representative sample of "well-scaled" values humans actually /// write in programs; in particular, it includes good coverage for integer values /// and values with short decimal parts. // func genExpDistributedFloat(significantDigits: Int) -> String { // let value = exp(Float80.random(in: 0...log(1000.0))) // return String(format: "%.\(significantDigits)f", Double(value)) // } /// Each workload contains 100 elements generated from the above function. let floatExpWorkload = [ "840.23812", "15.9082", "319.784", "13.14857", "5.42759", "901.771", "339.6", "7.27", "126.88", "326.08923", "18.2804", "189.8467", "330.628", "8.272461", "19.337", "12.0082", "29.6085", "27.4508", "5.14013", "725.388972", "124.102", "13.315556", "21.288", "45.4670", "88.7246", "6.16", "1.506155", "2.16918", "779.120", "22.89751", "15.33395", "59.575817", "2.73305", "203.04", "321.08", "148.419", "249.675", "579.453", "222.2", "153.62548", "305.501", "96.3", "28.55095", "145.377249", "2.53048", "1.0", "293.2052", "2.1", "814.091552", "157.45375", "15.0", "1.304", "8.88", "799.458180", "11.3", "1.5645", "25.69062", "569.28", "2.6464", "173.792970", "6.25", "344.54", "2.09610", "3.547", "409.860", "65.866038", "3.64", "2.7", "62.304", "67.7729", "19.0638", "2.8", "8.89508", "20.04", "1.054648", "3.5479", "5.203191", "52.11968", "326.39", "43.027", "82.15620", "178.519010", "1.3", "5.40", "387.41", "500.5", "5.96", "1.7740", "96.48818", "889.583", "96.92098", "6.760", "199.441", "510.905", "307.726", "87.9055", "11.7", "6.487537", "119.1", "5.8" ] let doubleExpWorkload = [ "339.91", "662.95264138", "590.3312546", "44.58449489426322", "1.61025794592574", "266.29744353690", "34.14542", "144.968532801343116", "1.790721486700", "609.0086620368", "1.79655054299720", "138.906589772754131", "1.3663343399933", "3.018134440821", "14.7117491216652", "97.0", "28.630149748915", "5.4", "29.7639", "4.520193", "43.574150740143", "21.26131766279", "8.332799002305356", "70.267", "792.71364", "987.54396679201125", "301.4300850", "707.7375522552", "3.350899864", "41.99", "78.051", "2.5251720", "28.171984464058", "6.115905648", "31.7", "2.90316715974825", "3.49235954808", "13.76", "3.2", "32.465845", "460.84828154", "1.0268532933", "79.607954332859777", "173.25041830", "49.0888", "23.2264", "130.018100263319411", "301.8", "1.707", "2.220651", "11.9744168", "13.50610", "83.276270711070708", "1.207", "11.507359", "887.81742700364475", "46.8051834077896", "174.367548608815781", "19.8671230", "5.0432", "3.927758869", "1.6393532610", "232.5", "17.77417107", "94.1453702714822", "746.2908548477199", "28.9832376533851", "1.7432454399", "96.15", "484.00318952955", "14.90238658606421", "243.704906310113", "29.5307828313724", "19.200405681021813", "24.1717308", "2.7453085963749", "2.856", "677.940804020", "221.57146165", "31.5891", "350.74206", "3.06588790579", "171.404", "46.106851", "590.3917781324", "829.052362588", "2.32566173", "7.0098461186", "306.11702882946065", "17.4345632593715", "899.3720935006996", "108.31212", "3.703786329", "48.81100281168", "27.41503", "169.15383", "1.978568", "3.68994208914", "29.4322212731893", "4.8719352" ] let float80ExpWorkload = [ "6.77555058241", "147.74", "6.03", "507.6033533228630859", "100.7", "11.46", "3.264282911002", "85.7858847516568", "34.4300032", "4.9957", "198.3958760", "87.67549428326", "205.373035358974988", "27.93", "831.999235134615", "46.886425395152", "5.77789", "89.564807063568139256", "3.85398054", "1.021", "592.504", "1.802084399", "486.4972328197284", "5.22490700277", "29.917340694598", "181.48302719", "75.74373681671689", "30.48161373580532", "1.24544077730", "1.2", "10.426", "55.37308819", "1.87502584", "3.1486", "9.2794677633", "24.59858334079387632", "20.2896643", "4.6", "9.017375215972097", "163.1", "5.50921892286", "9.93079", "13.320762298", "3.194056167117689693", "211.6671712762052380", "347.0356", "209.66", "13.170751077618", "34.568", "330.5", "41.388619513", "625.5176", "7.3199072376", "2.40", "334.210711370", "10.790469414612726240", "2.051865559526", "374.34104357856199", "1.444672057", "182.15138835680261", "1.549898719", "2.2", "3.5960392119", "220.3919", "128.45273", "955.052925", "441.738166", "21.365", "28.5534801613", "124.1", "449.252220495138", "608.587461250119532", "107.88473705800", "2.085422", "2.5", "121.0005042322", "5.4402224803576962", "90.46", "40.646406742621564945", "70.79133", "4.59801271236", "1.893481804014", "17.52333", "1.3195086968", "46.70781", "14.59891931096853", "402.75", "158.0343", "7.152603207", "7.3637945245", "15.6", "545.740720800777012", "242.172569", "1.73940415531105", "151.14631658", "26.5256384449273490", "135.236", "12.886101", "47.596174", "1.831407510" ] /// The 'Uniform' test: /// Generates values made up of uniform decimal significands with 9, 17 and 21 /// digits and exponents uniform on the valid range. This is a stress test /// for rounding, and covers all the worst cases for tables generated by programs. /// The exponent range is -45...38 for Floats, -324...308 for Doubles, and /// -4951...4932 for Float80. // func genUniformFloat(significandDigits: Int, exponentRange: ClosedRange) -> String { // let afterDecimalPoint = (0..(_ n: Int, workload: [String], type: T.Type) { for _ in 0..