From 33873284212e3530782fa785f1323e1d6acc70a6 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Thu, 20 Dec 2018 21:25:35 +0100 Subject: [PATCH 01/26] [Gardening] DataBenchmarks: quad to double space --- benchmark/single-source/DataBenchmarks.swift | 728 +++++++++---------- 1 file changed, 364 insertions(+), 364 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 1ccf8d721c8dd..c7604c1e8d8e9 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -14,106 +14,106 @@ import TestsUtils import Foundation public let DataBenchmarks = [ - BenchmarkInfo(name: "DataCreateEmpty", runFunction: run_createEmpty, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCreateSmall", runFunction: run_createSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCreateMedium", runFunction: run_createMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCreateLarge", runFunction: run_createLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataCreateEmptyArray", runFunction: run_createEmptyArray, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCreateSmallArray", runFunction: run_createSmallArray, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCreateMediumArray", runFunction: run_createMediumArray, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataSubscriptSmall", runFunction: run_SubscriptSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataSubscriptMedium", runFunction: run_SubscriptMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataSubscriptLarge", runFunction: run_SubscriptLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataCountSmall", runFunction: run_CountSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCountMedium", runFunction: run_CountMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCountLarge", runFunction: run_CountLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataSetCountSmall", runFunction: run_SetCountSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataSetCountMedium", runFunction: run_SetCountMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataSetCountLarge", runFunction: run_SetCountLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataAccessBytesSmall", runFunction: run_AccessBytesSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAccessBytesMedium", runFunction: run_AccessBytesMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAccessBytesLarge", runFunction: run_AccessBytesLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataMutateBytesSmall", runFunction: run_MutateBytesSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataMutateBytesMedium", runFunction: run_MutateBytesMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataMutateBytesLarge", runFunction: run_MutateBytesLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataCopyBytesSmall", runFunction: run_CopyBytesSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCopyBytesMedium", runFunction: run_CopyBytesMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCopyBytesLarge", runFunction: run_CopyBytesLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataAppendBytesSmall", runFunction: run_AppendBytesSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendBytesMedium", runFunction: run_AppendBytesMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendBytesLarge", runFunction: run_AppendBytesLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataAppendArray", runFunction: run_AppendArray, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReset", runFunction: run_Reset, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceSmall", runFunction: run_ReplaceSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceMedium", runFunction: run_ReplaceMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceLarge", runFunction: run_ReplaceLarge, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceSmallBuffer", runFunction: run_ReplaceSmallBuffer, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceMediumBuffer", runFunction: run_ReplaceMediumBuffer, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceLargeBuffer", runFunction: run_ReplaceLargeBuffer, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataAppendSequence", runFunction: run_AppendSequence, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataSmallToSmall", runFunction: run_AppendDataSmallToSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataSmallToMedium", runFunction: run_AppendDataSmallToMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataSmallToLarge", runFunction: run_AppendDataSmallToLarge, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataMediumToSmall", runFunction: run_AppendDataMediumToSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataMediumToMedium", runFunction: run_AppendDataMediumToMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataMediumToLarge", runFunction: run_AppendDataMediumToLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataAppendDataLargeToSmall", runFunction: run_AppendDataLargeToSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataLargeToMedium", runFunction: run_AppendDataLargeToMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataLargeToLarge", runFunction: run_AppendDataLargeToLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataToStringEmpty", runFunction: run_DataToStringEmpty, tags: [.validation, .api, .Data], legacyFactor: 50), - BenchmarkInfo(name: "DataToStringSmall", runFunction: run_DataToStringSmall, tags: [.validation, .api, .Data], legacyFactor: 50), - BenchmarkInfo(name: "DataToStringMedium", runFunction: run_DataToStringMedium, tags: [.validation, .api, .Data], legacyFactor: 50), - BenchmarkInfo(name: "StringToDataEmpty", runFunction: run_StringToDataEmpty, tags: [.validation, .api, .Data], legacyFactor: 50), - BenchmarkInfo(name: "StringToDataSmall", runFunction: run_StringToDataSmall, tags: [.validation, .api, .Data], legacyFactor: 50), - BenchmarkInfo(name: "StringToDataMedium", runFunction: run_StringToDataMedium, tags: [.validation, .api, .Data], legacyFactor: 50), + BenchmarkInfo(name: "DataCreateEmpty", runFunction: run_createEmpty, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataCreateSmall", runFunction: run_createSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataCreateMedium", runFunction: run_createMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataCreateLarge", runFunction: run_createLarge, tags: [.validation, .api, .Data, .skip]), + BenchmarkInfo(name: "DataCreateEmptyArray", runFunction: run_createEmptyArray, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataCreateSmallArray", runFunction: run_createSmallArray, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataCreateMediumArray", runFunction: run_createMediumArray, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataSubscriptSmall", runFunction: run_SubscriptSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataSubscriptMedium", runFunction: run_SubscriptMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataSubscriptLarge", runFunction: run_SubscriptLarge, tags: [.validation, .api, .Data, .skip]), + BenchmarkInfo(name: "DataCountSmall", runFunction: run_CountSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataCountMedium", runFunction: run_CountMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataCountLarge", runFunction: run_CountLarge, tags: [.validation, .api, .Data, .skip]), + BenchmarkInfo(name: "DataSetCountSmall", runFunction: run_SetCountSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataSetCountMedium", runFunction: run_SetCountMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataSetCountLarge", runFunction: run_SetCountLarge, tags: [.validation, .api, .Data, .skip]), + BenchmarkInfo(name: "DataAccessBytesSmall", runFunction: run_AccessBytesSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAccessBytesMedium", runFunction: run_AccessBytesMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAccessBytesLarge", runFunction: run_AccessBytesLarge, tags: [.validation, .api, .Data, .skip]), + BenchmarkInfo(name: "DataMutateBytesSmall", runFunction: run_MutateBytesSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataMutateBytesMedium", runFunction: run_MutateBytesMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataMutateBytesLarge", runFunction: run_MutateBytesLarge, tags: [.validation, .api, .Data, .skip]), + BenchmarkInfo(name: "DataCopyBytesSmall", runFunction: run_CopyBytesSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataCopyBytesMedium", runFunction: run_CopyBytesMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataCopyBytesLarge", runFunction: run_CopyBytesLarge, tags: [.validation, .api, .Data, .skip]), + BenchmarkInfo(name: "DataAppendBytesSmall", runFunction: run_AppendBytesSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAppendBytesMedium", runFunction: run_AppendBytesMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAppendBytesLarge", runFunction: run_AppendBytesLarge, tags: [.validation, .api, .Data, .skip]), + BenchmarkInfo(name: "DataAppendArray", runFunction: run_AppendArray, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataReset", runFunction: run_Reset, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataReplaceSmall", runFunction: run_ReplaceSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataReplaceMedium", runFunction: run_ReplaceMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataReplaceLarge", runFunction: run_ReplaceLarge, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataReplaceSmallBuffer", runFunction: run_ReplaceSmallBuffer, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataReplaceMediumBuffer", runFunction: run_ReplaceMediumBuffer, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataReplaceLargeBuffer", runFunction: run_ReplaceLargeBuffer, tags: [.validation, .api, .Data, .skip]), + BenchmarkInfo(name: "DataAppendSequence", runFunction: run_AppendSequence, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAppendDataSmallToSmall", runFunction: run_AppendDataSmallToSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAppendDataSmallToMedium", runFunction: run_AppendDataSmallToMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAppendDataSmallToLarge", runFunction: run_AppendDataSmallToLarge, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAppendDataMediumToSmall", runFunction: run_AppendDataMediumToSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAppendDataMediumToMedium", runFunction: run_AppendDataMediumToMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAppendDataMediumToLarge", runFunction: run_AppendDataMediumToLarge, tags: [.validation, .api, .Data, .skip]), + BenchmarkInfo(name: "DataAppendDataLargeToSmall", runFunction: run_AppendDataLargeToSmall, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAppendDataLargeToMedium", runFunction: run_AppendDataLargeToMedium, tags: [.validation, .api, .Data]), + BenchmarkInfo(name: "DataAppendDataLargeToLarge", runFunction: run_AppendDataLargeToLarge, tags: [.validation, .api, .Data, .skip]), + BenchmarkInfo(name: "DataToStringEmpty", runFunction: run_DataToStringEmpty, tags: [.validation, .api, .Data], legacyFactor: 50), + BenchmarkInfo(name: "DataToStringSmall", runFunction: run_DataToStringSmall, tags: [.validation, .api, .Data], legacyFactor: 50), + BenchmarkInfo(name: "DataToStringMedium", runFunction: run_DataToStringMedium, tags: [.validation, .api, .Data], legacyFactor: 50), + BenchmarkInfo(name: "StringToDataEmpty", runFunction: run_StringToDataEmpty, tags: [.validation, .api, .Data], legacyFactor: 50), + BenchmarkInfo(name: "StringToDataSmall", runFunction: run_StringToDataSmall, tags: [.validation, .api, .Data], legacyFactor: 50), + BenchmarkInfo(name: "StringToDataMedium", runFunction: run_StringToDataMedium, tags: [.validation, .api, .Data], legacyFactor: 50), ] enum SampleKind { - case small - case medium - case large - case veryLarge - case string - case immutableBacking + case small + case medium + case large + case veryLarge + case string + case immutableBacking } func sampleData(size: Int) -> Data { - var data = Data(count: size) - data.withUnsafeMutableBytes { getRandomBuf(baseAddress: $0, count: size) } - return data + var data = Data(count: size) + data.withUnsafeMutableBytes { getRandomBuf(baseAddress: $0, count: size) } + return data } func sampleString() -> Data { - let bytes: [UInt8] = [ - 0x4c,0x6f,0x72,0x65, 0x6d,0x20,0x69,0x70, 0x73,0x75,0x6d,0x20, 0x64,0x6f,0x6c,0x6f, - 0x72,0x20,0x73,0x69, 0x74,0x20,0x61,0x6d, 0x65,0x74,0x2c,0x20, 0x63,0x6f,0x6e,0x73, - 0x65,0x63,0x74,0x65, 0x74,0x75,0x72,0x20, 0x61,0x64,0x69,0x70, 0x69,0x73,0x69,0x63, - 0x69,0x6e,0x67,0x20, 0x65,0x6c,0x69,0x74, 0x2c,0x20,0x73,0x65, 0x64,0x20,0x64,0x6f, - 0x20,0x65,0x69,0x75, 0x73,0x6d,0x6f,0x64, 0x0a,0x74,0x65,0x6d, 0x70,0x6f,0x72,0x20, - 0x69,0x6e,0x63,0x69, 0x64,0x69,0x64,0x75, 0x6e,0x74,0x20,0x75, 0x74,0x20,0x6c,0x61, - 0x62,0x6f,0x72,0x65, 0x20,0x65,0x74,0x20, 0x64,0x6f,0x6c,0x6f, 0x72,0x65,0x20,0x6d, - 0x61,0x67,0x6e,0x61, 0x20,0x61,0x6c,0x69, 0x71,0x75,0x61,0x2e, 0x20,0x55,0x74,0x20, - 0x65,0x6e,0x69,0x6d, 0x20,0x61,0x64,0x20, 0x6d,0x69,0x6e,0x69, 0x6d,0x20,0x76,0x65, - 0x6e,0x69,0x61,0x6d, 0x2c,0x0a,0x71,0x75, 0x69,0x73,0x20,0x6e, 0x6f,0x73,0x74,0x72, - 0x75,0x64,0x20,0x65, 0x78,0x65,0x72,0x63, 0x69,0x74,0x61,0x74, 0x69,0x6f,0x6e,0x20, - 0x75,0x6c,0x6c,0x61, 0x6d,0x63,0x6f,0x20, 0x6c,0x61,0x62,0x6f, 0x72,0x69,0x73,0x20, - 0x6e,0x69,0x73,0x69, 0x20,0x75,0x74,0x20, 0x61,0x6c,0x69,0x71, 0x75,0x69,0x70,0x20, - 0x65,0x78,0x20,0x65, 0x61,0x20,0x63,0x6f, 0x6d,0x6d,0x6f,0x64, 0x6f,0x0a,0x63,0x6f, - 0x6e,0x73,0x65,0x71, 0x75,0x61,0x74,0x2e, 0x20,0x44,0x75,0x69, 0x73,0x20,0x61,0x75, - 0x74,0x65,0x20,0x69, 0x72,0x75,0x72,0x65, 0x20,0x64,0x6f,0x6c, 0x6f,0x72,0x20,0x69, - 0x6e,0x20,0x72,0x65, 0x70,0x72,0x65,0x68, 0x65,0x6e,0x64,0x65, 0x72,0x69,0x74,0x20, - 0x69,0x6e,0x20,0x76, 0x6f,0x6c,0x75,0x70, 0x74,0x61,0x74,0x65, 0x20,0x76,0x65,0x6c, - 0x69,0x74,0x20,0x65, 0x73,0x73,0x65,0x0a, 0x63,0x69,0x6c,0x6c, 0x75,0x6d,0x20,0x64, - 0x6f,0x6c,0x6f,0x72, 0x65,0x20,0x65,0x75, 0x20,0x66,0x75,0x67, 0x69,0x61,0x74,0x20, - 0x6e,0x75,0x6c,0x6c, 0x61,0x20,0x70,0x61, 0x72,0x69,0x61,0x74, 0x75,0x72,0x2e,0x20, - 0x45,0x78,0x63,0x65, 0x70,0x74,0x65,0x75, 0x72,0x20,0x73,0x69, 0x6e,0x74,0x20,0x6f, - 0x63,0x63,0x61,0x65, 0x63,0x61,0x74,0x20, 0x63,0x75,0x70,0x69, 0x64,0x61,0x74,0x61, - 0x74,0x20,0x6e,0x6f, 0x6e,0x0a,0x70,0x72, 0x6f,0x69,0x64,0x65, 0x6e,0x74,0x2c,0x20, - 0x73,0x75,0x6e,0x74, 0x20,0x69,0x6e,0x20, 0x63,0x75,0x6c,0x70, 0x61,0x20,0x71,0x75, - 0x69,0x20,0x6f,0x66, 0x66,0x69,0x63,0x69, 0x61,0x20,0x64,0x65, 0x73,0x65,0x72,0x75, - 0x6e,0x74,0x20,0x6d, 0x6f,0x6c,0x6c,0x69, 0x74,0x20,0x61,0x6e, 0x69,0x6d,0x20,0x69, - 0x64,0x20,0x65,0x73, 0x74,0x20,0x6c,0x61, 0x62,0x6f,0x72,0x75, 0x6d,0x2e,0x0a,0x00] - return Data(bytes: bytes) + let bytes: [UInt8] = [ + 0x4c,0x6f,0x72,0x65, 0x6d,0x20,0x69,0x70, 0x73,0x75,0x6d,0x20, 0x64,0x6f,0x6c,0x6f, + 0x72,0x20,0x73,0x69, 0x74,0x20,0x61,0x6d, 0x65,0x74,0x2c,0x20, 0x63,0x6f,0x6e,0x73, + 0x65,0x63,0x74,0x65, 0x74,0x75,0x72,0x20, 0x61,0x64,0x69,0x70, 0x69,0x73,0x69,0x63, + 0x69,0x6e,0x67,0x20, 0x65,0x6c,0x69,0x74, 0x2c,0x20,0x73,0x65, 0x64,0x20,0x64,0x6f, + 0x20,0x65,0x69,0x75, 0x73,0x6d,0x6f,0x64, 0x0a,0x74,0x65,0x6d, 0x70,0x6f,0x72,0x20, + 0x69,0x6e,0x63,0x69, 0x64,0x69,0x64,0x75, 0x6e,0x74,0x20,0x75, 0x74,0x20,0x6c,0x61, + 0x62,0x6f,0x72,0x65, 0x20,0x65,0x74,0x20, 0x64,0x6f,0x6c,0x6f, 0x72,0x65,0x20,0x6d, + 0x61,0x67,0x6e,0x61, 0x20,0x61,0x6c,0x69, 0x71,0x75,0x61,0x2e, 0x20,0x55,0x74,0x20, + 0x65,0x6e,0x69,0x6d, 0x20,0x61,0x64,0x20, 0x6d,0x69,0x6e,0x69, 0x6d,0x20,0x76,0x65, + 0x6e,0x69,0x61,0x6d, 0x2c,0x0a,0x71,0x75, 0x69,0x73,0x20,0x6e, 0x6f,0x73,0x74,0x72, + 0x75,0x64,0x20,0x65, 0x78,0x65,0x72,0x63, 0x69,0x74,0x61,0x74, 0x69,0x6f,0x6e,0x20, + 0x75,0x6c,0x6c,0x61, 0x6d,0x63,0x6f,0x20, 0x6c,0x61,0x62,0x6f, 0x72,0x69,0x73,0x20, + 0x6e,0x69,0x73,0x69, 0x20,0x75,0x74,0x20, 0x61,0x6c,0x69,0x71, 0x75,0x69,0x70,0x20, + 0x65,0x78,0x20,0x65, 0x61,0x20,0x63,0x6f, 0x6d,0x6d,0x6f,0x64, 0x6f,0x0a,0x63,0x6f, + 0x6e,0x73,0x65,0x71, 0x75,0x61,0x74,0x2e, 0x20,0x44,0x75,0x69, 0x73,0x20,0x61,0x75, + 0x74,0x65,0x20,0x69, 0x72,0x75,0x72,0x65, 0x20,0x64,0x6f,0x6c, 0x6f,0x72,0x20,0x69, + 0x6e,0x20,0x72,0x65, 0x70,0x72,0x65,0x68, 0x65,0x6e,0x64,0x65, 0x72,0x69,0x74,0x20, + 0x69,0x6e,0x20,0x76, 0x6f,0x6c,0x75,0x70, 0x74,0x61,0x74,0x65, 0x20,0x76,0x65,0x6c, + 0x69,0x74,0x20,0x65, 0x73,0x73,0x65,0x0a, 0x63,0x69,0x6c,0x6c, 0x75,0x6d,0x20,0x64, + 0x6f,0x6c,0x6f,0x72, 0x65,0x20,0x65,0x75, 0x20,0x66,0x75,0x67, 0x69,0x61,0x74,0x20, + 0x6e,0x75,0x6c,0x6c, 0x61,0x20,0x70,0x61, 0x72,0x69,0x61,0x74, 0x75,0x72,0x2e,0x20, + 0x45,0x78,0x63,0x65, 0x70,0x74,0x65,0x75, 0x72,0x20,0x73,0x69, 0x6e,0x74,0x20,0x6f, + 0x63,0x63,0x61,0x65, 0x63,0x61,0x74,0x20, 0x63,0x75,0x70,0x69, 0x64,0x61,0x74,0x61, + 0x74,0x20,0x6e,0x6f, 0x6e,0x0a,0x70,0x72, 0x6f,0x69,0x64,0x65, 0x6e,0x74,0x2c,0x20, + 0x73,0x75,0x6e,0x74, 0x20,0x69,0x6e,0x20, 0x63,0x75,0x6c,0x70, 0x61,0x20,0x71,0x75, + 0x69,0x20,0x6f,0x66, 0x66,0x69,0x63,0x69, 0x61,0x20,0x64,0x65, 0x73,0x65,0x72,0x75, + 0x6e,0x74,0x20,0x6d, 0x6f,0x6c,0x6c,0x69, 0x74,0x20,0x61,0x6e, 0x69,0x6d,0x20,0x69, + 0x64,0x20,0x65,0x73, 0x74,0x20,0x6c,0x61, 0x62,0x6f,0x72,0x75, 0x6d,0x2e,0x0a,0x00] + return Data(bytes: bytes) } #if os(Linux) @@ -122,529 +122,529 @@ import Glibc @inline(__always) func getRandomBuf(_ arg: UnsafeMutableBufferPointer) { - #if os(Linux) - let fd = open("/dev/urandom", O_RDONLY) - defer { if (fd >= 0) { close(fd) } } - if fd >= 0 { - read(fd, arg.baseAddress, arg.count) - } - #else - arc4random_buf(arg.baseAddress, arg.count) - #endif + #if os(Linux) + let fd = open("/dev/urandom", O_RDONLY) + defer { if (fd >= 0) { close(fd) } } + if fd >= 0 { + read(fd, arg.baseAddress, arg.count) + } + #else + arc4random_buf(arg.baseAddress, arg.count) + #endif } @inline(__always) func getRandomBuf(baseAddress: UnsafeMutablePointer, count: Int) { - #if os(Linux) - let fd = open("/dev/urandom", O_RDONLY) - defer { if (fd >= 0) { close(fd) } } - if fd >= 0 { - read(fd, baseAddress, count) - } - #else - arc4random_buf(baseAddress, count) - #endif + #if os(Linux) + let fd = open("/dev/urandom", O_RDONLY) + defer { if (fd >= 0) { close(fd) } } + if fd >= 0 { + read(fd, baseAddress, count) + } + #else + arc4random_buf(baseAddress, count) + #endif } func sampleBridgedNSData() -> Data { - let count = 1033 - var bytes = [UInt8](repeating: 0, count: count) - bytes.withUnsafeMutableBufferPointer { - getRandomBuf($0) - } - let data = NSData(bytes: bytes, length: count) - return Data(referencing: data) + let count = 1033 + var bytes = [UInt8](repeating: 0, count: count) + bytes.withUnsafeMutableBufferPointer { + getRandomBuf($0) + } + let data = NSData(bytes: bytes, length: count) + return Data(referencing: data) } func sampleData(_ type: SampleKind) -> Data { - switch type { - case .small: return sampleData(size: 11) - case .medium: return sampleData(size: 1033) - case .large: return sampleData(size: 40980) - case .veryLarge: return sampleData(size: 1024 * 1024 * 1024 + 128) - case .string: return sampleString() - case .immutableBacking: return sampleBridgedNSData() - } + switch type { + case .small: return sampleData(size: 11) + case .medium: return sampleData(size: 1033) + case .large: return sampleData(size: 40980) + case .veryLarge: return sampleData(size: 1024 * 1024 * 1024 + 128) + case .string: return sampleString() + case .immutableBacking: return sampleBridgedNSData() + } } func benchmark_AccessBytes(_ N: Int, _ data: Data) { - for _ in 0..<10000*N { - data.withUnsafeBytes { (ptr: UnsafePointer) in - // Ensure that the compiler does not optimize away this call - blackHole(ptr.pointee) - } + for _ in 0..<10000*N { + data.withUnsafeBytes { (ptr: UnsafePointer) in + // Ensure that the compiler does not optimize away this call + blackHole(ptr.pointee) } + } } func benchmark_MutateBytes(_ N: Int, _ data_: Data) { - for _ in 0..<10000*N { - var data = data_ - data.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer) in - // Mutate a byte - ptr.pointee = 42 - } + for _ in 0..<10000*N { + var data = data_ + data.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer) in + // Mutate a byte + ptr.pointee = 42 } + } } func benchmark_CopyBytes(_ N: Int, _ data: Data) { - let amount = data.count - var buffer = UnsafeMutablePointer.allocate(capacity: amount) - defer { buffer.deallocate() } - for _ in 0..<10000*N { - data.copyBytes(to: buffer, from: 0...allocate(capacity: amount) + defer { buffer.deallocate() } + for _ in 0..<10000*N { + data.copyBytes(to: buffer, from: 0.., _ data_: Data) { - for _ in 0..<10000*N { - var data = data_ - data.resetBytes(in: range) - } + for _ in 0..<10000*N { + var data = data_ + data.resetBytes(in: range) + } } func benchmark_Replace(_ N: Int, _ range: Range, _ data_: Data, _ replacement: Data) { - for _ in 0..<10000*N { - var data = data_ - data.replaceSubrange(range, with: replacement) - } + for _ in 0..<10000*N { + var data = data_ + data.replaceSubrange(range, with: replacement) + } } func benchmark_ReplaceBuffer(_ N: Int, _ range: Range, _ data_: Data, _ replacement: UnsafeBufferPointer) { - for _ in 0..<10000*N { - var data = data_ - data.replaceSubrange(range, with: replacement) - } + for _ in 0..<10000*N { + var data = data_ + data.replaceSubrange(range, with: replacement) + } } func benchmark_AppendData(_ N: Int, _ lhs: Data, _ rhs: Data) { - var data = lhs - for _ in 0..<10000*N { - data = lhs - data.append(rhs) - } + var data = lhs + for _ in 0..<10000*N { + data = lhs + data.append(rhs) + } } @inline(never) public func run_SubscriptSmall(_ N: Int) { - let data = sampleData(.small) - let index = 1 - for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call - blackHole(data[index]) - } + let data = sampleData(.small) + let index = 1 + for _ in 0..<10000*N { + // Ensure that the compiler does not optimize away this call + blackHole(data[index]) + } } @inline(never) public func run_SubscriptMedium(_ N: Int) { - let data = sampleData(.medium) - let index = 521 - for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call - blackHole(data[index]) - } + let data = sampleData(.medium) + let index = 521 + for _ in 0..<10000*N { + // Ensure that the compiler does not optimize away this call + blackHole(data[index]) + } } @inline(never) public func run_SubscriptLarge(_ N: Int) { - let data = sampleData(.veryLarge) - let index = 521 - for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call - blackHole(data[index]) - } + let data = sampleData(.veryLarge) + let index = 521 + for _ in 0..<10000*N { + // Ensure that the compiler does not optimize away this call + blackHole(data[index]) + } } @inline(never) public func run_CountSmall(_ N: Int) { - let data = sampleData(.small) - for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call - blackHole(data.count) - } + let data = sampleData(.small) + for _ in 0..<10000*N { + // Ensure that the compiler does not optimize away this call + blackHole(data.count) + } } @inline(never) public func run_CountMedium(_ N: Int) { - let data = sampleData(.medium) - for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call - blackHole(data.count) - } + let data = sampleData(.medium) + for _ in 0..<10000*N { + // Ensure that the compiler does not optimize away this call + blackHole(data.count) + } } @inline(never) public func run_CountLarge(_ N: Int) { - let data = sampleData(.veryLarge) - for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call - blackHole(data.count) - } + let data = sampleData(.veryLarge) + for _ in 0..<10000*N { + // Ensure that the compiler does not optimize away this call + blackHole(data.count) + } } @inline(never) public func run_SetCountSmall(_ N: Int) { - var data = sampleData(.small) - let count = data.count + 3 - let orig = data.count - for _ in 0..<10000*N { - data.count = count - data.count = orig - } + var data = sampleData(.small) + let count = data.count + 3 + let orig = data.count + for _ in 0..<10000*N { + data.count = count + data.count = orig + } } @inline(never) public func run_SetCountMedium(_ N: Int) { - var data = sampleData(.medium) - let count = data.count + 100 - let orig = data.count - for _ in 0..<10000*N { - data.count = count - data.count = orig - } + var data = sampleData(.medium) + let count = data.count + 100 + let orig = data.count + for _ in 0..<10000*N { + data.count = count + data.count = orig + } } @inline(never) public func run_SetCountLarge(_ N: Int) { - var data = sampleData(.large) - let count = data.count + 100 - let orig = data.count - for _ in 0..<10000*N { - data.count = count - data.count = orig - } + var data = sampleData(.large) + let count = data.count + 100 + let orig = data.count + for _ in 0..<10000*N { + data.count = count + data.count = orig + } } @inline(never) public func run_AccessBytesSmall(_ N: Int) { - let data = sampleData(.small) - benchmark_AccessBytes(N, data) + let data = sampleData(.small) + benchmark_AccessBytes(N, data) } @inline(never) public func run_AccessBytesMedium(_ N: Int) { - let data = sampleData(.medium) - benchmark_AccessBytes(N, data) + let data = sampleData(.medium) + benchmark_AccessBytes(N, data) } @inline(never) public func run_AccessBytesLarge(_ N: Int) { - let data = sampleData(.veryLarge) - benchmark_AccessBytes(N, data) + let data = sampleData(.veryLarge) + benchmark_AccessBytes(N, data) } @inline(never) public func run_MutateBytesSmall(_ N: Int) { - let data = sampleData(.small) - benchmark_MutateBytes(N, data) + let data = sampleData(.small) + benchmark_MutateBytes(N, data) } @inline(never) public func run_MutateBytesMedium(_ N: Int) { - let data = sampleData(.medium) - benchmark_MutateBytes(N, data) + let data = sampleData(.medium) + benchmark_MutateBytes(N, data) } @inline(never) public func run_MutateBytesLarge(_ N: Int) { - let data = sampleData(.veryLarge) - benchmark_MutateBytes(N, data) + let data = sampleData(.veryLarge) + benchmark_MutateBytes(N, data) } @inline(never) public func run_CopyBytesSmall(_ N: Int) { - let data = sampleData(.small) - benchmark_CopyBytes(N, data) + let data = sampleData(.small) + benchmark_CopyBytes(N, data) } @inline(never) public func run_CopyBytesMedium(_ N: Int) { - let data = sampleData(.medium) - benchmark_CopyBytes(N, data) + let data = sampleData(.medium) + benchmark_CopyBytes(N, data) } @inline(never) public func run_CopyBytesLarge(_ N: Int) { - let data = sampleData(.large) - benchmark_CopyBytes(N, data) + let data = sampleData(.large) + benchmark_CopyBytes(N, data) } @inline(never) public func run_AppendBytesSmall(_ N: Int) { - let data = sampleData(.small) - benchmark_AppendBytes(N, 3, data) + let data = sampleData(.small) + benchmark_AppendBytes(N, 3, data) } @inline(never) public func run_AppendBytesMedium(_ N: Int) { - let data = sampleData(.medium) - benchmark_AppendBytes(N, 809, data) + let data = sampleData(.medium) + benchmark_AppendBytes(N, 809, data) } @inline(never) public func run_AppendBytesLarge(_ N: Int) { - let data = sampleData(.veryLarge) - benchmark_AppendBytes(N, 809, data) + let data = sampleData(.veryLarge) + benchmark_AppendBytes(N, 809, data) } @inline(never) public func run_AppendArray(_ N: Int) { - let data = sampleData(.medium) - benchmark_AppendArray(N, 809, data) + let data = sampleData(.medium) + benchmark_AppendArray(N, 809, data) } @inline(never) public func run_Reset(_ N: Int) { - let data = sampleData(.medium) - benchmark_Reset(N, 431..<809, data) + let data = sampleData(.medium) + benchmark_Reset(N, 431..<809, data) } @inline(never) public func run_ReplaceSmall(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.small) - benchmark_Replace(N, 431..<809, data, replacement) + let data = sampleData(.medium) + let replacement = sampleData(.small) + benchmark_Replace(N, 431..<809, data, replacement) } @inline(never) public func run_ReplaceMedium(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.medium) - benchmark_Replace(N, 431..<809, data, replacement) + let data = sampleData(.medium) + let replacement = sampleData(.medium) + benchmark_Replace(N, 431..<809, data, replacement) } @inline(never) public func run_ReplaceLarge(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.large) - benchmark_Replace(N, 431..<809, data, replacement) + let data = sampleData(.medium) + let replacement = sampleData(.large) + benchmark_Replace(N, 431..<809, data, replacement) } @inline(never) public func run_ReplaceSmallBuffer(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.small) - let sz = replacement.count - replacement.withUnsafeBytes { (ptr: UnsafePointer) in - benchmark_ReplaceBuffer(N, 431..<809, data, UnsafeBufferPointer(start: ptr, count: sz)) - } + let data = sampleData(.medium) + let replacement = sampleData(.small) + let sz = replacement.count + replacement.withUnsafeBytes { (ptr: UnsafePointer) in + benchmark_ReplaceBuffer(N, 431..<809, data, UnsafeBufferPointer(start: ptr, count: sz)) + } } @inline(never) public func run_ReplaceMediumBuffer(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.medium) - let sz = replacement.count - replacement.withUnsafeBytes { (ptr: UnsafePointer) in - benchmark_ReplaceBuffer(N, 431..<809, data, UnsafeBufferPointer(start: ptr, count: sz)) - } + let data = sampleData(.medium) + let replacement = sampleData(.medium) + let sz = replacement.count + replacement.withUnsafeBytes { (ptr: UnsafePointer) in + benchmark_ReplaceBuffer(N, 431..<809, data, UnsafeBufferPointer(start: ptr, count: sz)) + } } @inline(never) public func run_ReplaceLargeBuffer(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.large) - let sz = replacement.count - replacement.withUnsafeBytes { (ptr: UnsafePointer) in - benchmark_ReplaceBuffer(N, 431..<809, data, UnsafeBufferPointer(start: ptr, count: sz)) - } + let data = sampleData(.medium) + let replacement = sampleData(.large) + let sz = replacement.count + replacement.withUnsafeBytes { (ptr: UnsafePointer) in + benchmark_ReplaceBuffer(N, 431..<809, data, UnsafeBufferPointer(start: ptr, count: sz)) + } } @inline(never) public func run_AppendSequence(_ N: Int) { - let data = sampleData(.medium) - benchmark_AppendSequence(N, 809, data) + let data = sampleData(.medium) + benchmark_AppendSequence(N, 809, data) } @inline(never) public func run_AppendDataSmallToSmall(_ N: Int) { - let data = sampleData(.small) - let other = sampleData(.small) - benchmark_AppendData(N, data, other) + let data = sampleData(.small) + let other = sampleData(.small) + benchmark_AppendData(N, data, other) } @inline(never) public func run_AppendDataSmallToMedium(_ N: Int) { - let data = sampleData(.medium) - let other = sampleData(.small) - benchmark_AppendData(N, data, other) + let data = sampleData(.medium) + let other = sampleData(.small) + benchmark_AppendData(N, data, other) } @inline(never) public func run_AppendDataSmallToLarge(_ N: Int) { - let data = sampleData(.large) - let other = sampleData(.small) - benchmark_AppendData(N, data, other) + let data = sampleData(.large) + let other = sampleData(.small) + benchmark_AppendData(N, data, other) } @inline(never) public func run_AppendDataMediumToSmall(_ N: Int) { - let data = sampleData(.small) - let other = sampleData(.medium) - benchmark_AppendData(N, data, other) + let data = sampleData(.small) + let other = sampleData(.medium) + benchmark_AppendData(N, data, other) } @inline(never) public func run_AppendDataMediumToMedium(_ N: Int) { - let data = sampleData(.medium) - let other = sampleData(.medium) - benchmark_AppendData(N, data, other) + let data = sampleData(.medium) + let other = sampleData(.medium) + benchmark_AppendData(N, data, other) } @inline(never) public func run_AppendDataMediumToLarge(_ N: Int) { - let data = sampleData(.large) - let other = sampleData(.medium) - benchmark_AppendData(N, data, other) + let data = sampleData(.large) + let other = sampleData(.medium) + benchmark_AppendData(N, data, other) } @inline(never) public func run_AppendDataLargeToSmall(_ N: Int) { - let data = sampleData(.small) - let other = sampleData(.large) - benchmark_AppendData(N, data, other) + let data = sampleData(.small) + let other = sampleData(.large) + benchmark_AppendData(N, data, other) } @inline(never) public func run_AppendDataLargeToMedium(_ N: Int) { - let data = sampleData(.medium) - let other = sampleData(.large) - benchmark_AppendData(N, data, other) + let data = sampleData(.medium) + let other = sampleData(.large) + benchmark_AppendData(N, data, other) } @inline(never) public func run_AppendDataLargeToLarge(_ N: Int) { - let data = sampleData(.large) - let other = sampleData(.large) - benchmark_AppendData(N, data, other) + let data = sampleData(.large) + let other = sampleData(.large) + benchmark_AppendData(N, data, other) } @inline(never) public func run_createEmpty(_ N: Int) { - for _ in 0..<100000 * N { - blackHole(Data()) - } + for _ in 0..<100000 * N { + blackHole(Data()) + } } @inline(never) public func run_createSmall(_ N: Int) { - for _ in 0..<100000 * N { - blackHole(sampleData(.small)) - } + for _ in 0..<100000 * N { + blackHole(sampleData(.small)) + } } @inline(never) public func run_createMedium(_ N: Int) { - for _ in 0..<10000 * N { - blackHole(sampleData(.medium)) - } + for _ in 0..<10000 * N { + blackHole(sampleData(.medium)) + } } @inline(never) public func run_createLarge(_ N: Int) { - blackHole(sampleData(.veryLarge)) + blackHole(sampleData(.veryLarge)) } @inline(never) public func run_createEmptyArray(_ N: Int) { - for _ in 0..<100000 * N { - blackHole(Data([])) - } + for _ in 0..<100000 * N { + blackHole(Data([])) + } } @inline(never) public func run_createSmallArray(_ N: Int) { - for _ in 0..<100000 * N { - blackHole(Data([0, 1, 2, 3, 4, 5, 6])) - } + for _ in 0..<100000 * N { + blackHole(Data([0, 1, 2, 3, 4, 5, 6])) + } } @inline(never) public func run_createMediumArray(_ N: Int) { - for _ in 0..<10000 * N { - blackHole(Data([0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6])) - } + for _ in 0..<10000 * N { + blackHole(Data([0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6])) + } } @inline(never) public func run_DataToStringEmpty(_ N: Int) { - let d = Data() - for _ in 0..<200 * N { - let s = String(decoding: d, as: UTF8.self) - blackHole(s) - } + let d = Data() + for _ in 0..<200 * N { + let s = String(decoding: d, as: UTF8.self) + blackHole(s) + } } @inline(never) public func run_DataToStringSmall(_ N: Int) { - let d = Data([0x0D, 0x0A]) - for _ in 0..<200 * N { - let s = String(decoding: d, as: UTF8.self) - blackHole(s) - } + let d = Data([0x0D, 0x0A]) + for _ in 0..<200 * N { + let s = String(decoding: d, as: UTF8.self) + blackHole(s) + } } @inline(never) public func run_DataToStringMedium(_ N: Int) { - let d = Data([0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A]) - for _ in 0..<200 * N { - let s = String(decoding: d, as: UTF8.self) - blackHole(s) - } + let d = Data([0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A]) + for _ in 0..<200 * N { + let s = String(decoding: d, as: UTF8.self) + blackHole(s) + } } @inline(never) public func run_StringToDataEmpty(_ N: Int) { - let s = "" - for _ in 0..<200 * N { - let d = Data(s.utf8) - blackHole(d) - } + let s = "" + for _ in 0..<200 * N { + let d = Data(s.utf8) + blackHole(d) + } } @inline(never) public func run_StringToDataSmall(_ N: Int) { - let s = "\r\n" - for _ in 0..<200 * N { - let d = Data(s.utf8) - blackHole(d) - } + let s = "\r\n" + for _ in 0..<200 * N { + let d = Data(s.utf8) + blackHole(d) + } } @inline(never) public func run_StringToDataMedium(_ N: Int) { - let s = "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" - for _ in 0..<200 * N { - let d = Data(s.utf8) - blackHole(d) - } + let s = "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + for _ in 0..<200 * N { + let d = Data(s.utf8) + blackHole(d) + } } From c007844bbd8274abcc4221595de1147301d1be8f Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Thu, 20 Dec 2018 23:53:25 +0100 Subject: [PATCH 02/26] [Gardening] DataBenchmarks: format BenchmarkInfo --- benchmark/single-source/DataBenchmarks.swift | 177 +++++++++++++------ 1 file changed, 124 insertions(+), 53 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index c7604c1e8d8e9..7ac64a646afa8 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -1,4 +1,4 @@ -//===--- DataBenchmarks.swift ---------------------------------------------------===// +//===--- DataBenchmarks.swift ---------------------------------------------===// // // This source file is part of the Swift.org open source project // @@ -13,59 +13,130 @@ import TestsUtils import Foundation +let d: [BenchmarkCategory] = [.validation, .api, .Data] +let skip: [BenchmarkCategory] = [.validation, .api, .Data, .skip] + public let DataBenchmarks = [ - BenchmarkInfo(name: "DataCreateEmpty", runFunction: run_createEmpty, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCreateSmall", runFunction: run_createSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCreateMedium", runFunction: run_createMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCreateLarge", runFunction: run_createLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataCreateEmptyArray", runFunction: run_createEmptyArray, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCreateSmallArray", runFunction: run_createSmallArray, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCreateMediumArray", runFunction: run_createMediumArray, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataSubscriptSmall", runFunction: run_SubscriptSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataSubscriptMedium", runFunction: run_SubscriptMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataSubscriptLarge", runFunction: run_SubscriptLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataCountSmall", runFunction: run_CountSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCountMedium", runFunction: run_CountMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCountLarge", runFunction: run_CountLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataSetCountSmall", runFunction: run_SetCountSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataSetCountMedium", runFunction: run_SetCountMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataSetCountLarge", runFunction: run_SetCountLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataAccessBytesSmall", runFunction: run_AccessBytesSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAccessBytesMedium", runFunction: run_AccessBytesMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAccessBytesLarge", runFunction: run_AccessBytesLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataMutateBytesSmall", runFunction: run_MutateBytesSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataMutateBytesMedium", runFunction: run_MutateBytesMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataMutateBytesLarge", runFunction: run_MutateBytesLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataCopyBytesSmall", runFunction: run_CopyBytesSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCopyBytesMedium", runFunction: run_CopyBytesMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataCopyBytesLarge", runFunction: run_CopyBytesLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataAppendBytesSmall", runFunction: run_AppendBytesSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendBytesMedium", runFunction: run_AppendBytesMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendBytesLarge", runFunction: run_AppendBytesLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataAppendArray", runFunction: run_AppendArray, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReset", runFunction: run_Reset, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceSmall", runFunction: run_ReplaceSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceMedium", runFunction: run_ReplaceMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceLarge", runFunction: run_ReplaceLarge, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceSmallBuffer", runFunction: run_ReplaceSmallBuffer, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceMediumBuffer", runFunction: run_ReplaceMediumBuffer, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataReplaceLargeBuffer", runFunction: run_ReplaceLargeBuffer, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataAppendSequence", runFunction: run_AppendSequence, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataSmallToSmall", runFunction: run_AppendDataSmallToSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataSmallToMedium", runFunction: run_AppendDataSmallToMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataSmallToLarge", runFunction: run_AppendDataSmallToLarge, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataMediumToSmall", runFunction: run_AppendDataMediumToSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataMediumToMedium", runFunction: run_AppendDataMediumToMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataMediumToLarge", runFunction: run_AppendDataMediumToLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataAppendDataLargeToSmall", runFunction: run_AppendDataLargeToSmall, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataLargeToMedium", runFunction: run_AppendDataLargeToMedium, tags: [.validation, .api, .Data]), - BenchmarkInfo(name: "DataAppendDataLargeToLarge", runFunction: run_AppendDataLargeToLarge, tags: [.validation, .api, .Data, .skip]), - BenchmarkInfo(name: "DataToStringEmpty", runFunction: run_DataToStringEmpty, tags: [.validation, .api, .Data], legacyFactor: 50), - BenchmarkInfo(name: "DataToStringSmall", runFunction: run_DataToStringSmall, tags: [.validation, .api, .Data], legacyFactor: 50), - BenchmarkInfo(name: "DataToStringMedium", runFunction: run_DataToStringMedium, tags: [.validation, .api, .Data], legacyFactor: 50), - BenchmarkInfo(name: "StringToDataEmpty", runFunction: run_StringToDataEmpty, tags: [.validation, .api, .Data], legacyFactor: 50), - BenchmarkInfo(name: "StringToDataSmall", runFunction: run_StringToDataSmall, tags: [.validation, .api, .Data], legacyFactor: 50), - BenchmarkInfo(name: "StringToDataMedium", runFunction: run_StringToDataMedium, tags: [.validation, .api, .Data], legacyFactor: 50), + BenchmarkInfo(name: "DataCreateEmpty", + runFunction: run_createEmpty, tags: d), + BenchmarkInfo(name: "DataCreateSmall", + runFunction: run_createSmall, tags: d), + BenchmarkInfo(name: "DataCreateMedium", + runFunction: run_createMedium, tags: d), + BenchmarkInfo(name: "DataCreateLarge", + runFunction: run_createLarge, tags: skip), + + BenchmarkInfo(name: "DataCreateEmptyArray", + runFunction: run_createEmptyArray, tags: d), + BenchmarkInfo(name: "DataCreateSmallArray", + runFunction: run_createSmallArray, tags: d), + BenchmarkInfo(name: "DataCreateMediumArray", + runFunction: run_createMediumArray, tags: d), + + BenchmarkInfo(name: "DataSubscriptSmall", + runFunction: run_SubscriptSmall, tags: d), + BenchmarkInfo(name: "DataSubscriptMedium", + runFunction: run_SubscriptMedium, tags: d), + BenchmarkInfo(name: "DataSubscriptLarge", + runFunction: run_SubscriptLarge, tags: skip), + + BenchmarkInfo(name: "DataCountSmall", + runFunction: run_CountSmall, tags: d), + BenchmarkInfo(name: "DataCountMedium", + runFunction: run_CountMedium, tags: d), + BenchmarkInfo(name: "DataCountLarge", + runFunction: run_CountLarge, tags: skip), + + BenchmarkInfo(name: "DataSetCountSmall", + runFunction: run_SetCountSmall, tags: d), + BenchmarkInfo(name: "DataSetCountMedium", + runFunction: run_SetCountMedium, tags: d), + BenchmarkInfo(name: "DataSetCountLarge", + runFunction: run_SetCountLarge, tags: skip), + + BenchmarkInfo(name: "DataAccessBytesSmall", + runFunction: run_AccessBytesSmall, tags: d), + BenchmarkInfo(name: "DataAccessBytesMedium", + runFunction: run_AccessBytesMedium, tags: d), + BenchmarkInfo(name: "DataAccessBytesLarge", + runFunction: run_AccessBytesLarge, tags: skip), + + BenchmarkInfo(name: "DataMutateBytesSmall", + runFunction: run_MutateBytesSmall, tags: d), + BenchmarkInfo(name: "DataMutateBytesMedium", + runFunction: run_MutateBytesMedium, tags: d), + BenchmarkInfo(name: "DataMutateBytesLarge", + runFunction: run_MutateBytesLarge, tags: skip), + + BenchmarkInfo(name: "DataCopyBytesSmall", + runFunction: run_CopyBytesSmall, tags: d), + BenchmarkInfo(name: "DataCopyBytesMedium", + runFunction: run_CopyBytesMedium, tags: d), + BenchmarkInfo(name: "DataCopyBytesLarge", + runFunction: run_CopyBytesLarge, tags: skip), + + BenchmarkInfo(name: "DataAppendBytesSmall", + runFunction: run_AppendBytesSmall, tags: d), + BenchmarkInfo(name: "DataAppendBytesMedium", + runFunction: run_AppendBytesMedium, tags: d), + BenchmarkInfo(name: "DataAppendBytesLarge", + runFunction: run_AppendBytesLarge, tags: skip), + + BenchmarkInfo(name: "DataAppendArray", + runFunction: run_AppendArray, tags: d), + + BenchmarkInfo(name: "DataReset", + runFunction: run_Reset, tags: d), + + BenchmarkInfo(name: "DataReplaceSmall", + runFunction: run_ReplaceSmall, tags: d), + BenchmarkInfo(name: "DataReplaceMedium", + runFunction: run_ReplaceMedium, tags: d), + BenchmarkInfo(name: "DataReplaceLarge", + runFunction: run_ReplaceLarge, tags: d), + + BenchmarkInfo(name: "DataReplaceSmallBuffer", + runFunction: run_ReplaceSmallBuffer, tags: d), + BenchmarkInfo(name: "DataReplaceMediumBuffer", + runFunction: run_ReplaceMediumBuffer, tags: d), + BenchmarkInfo(name: "DataReplaceLargeBuffer", + runFunction: run_ReplaceLargeBuffer, tags: skip), + + BenchmarkInfo(name: "DataAppendSequence", + runFunction: run_AppendSequence, tags: d), + + BenchmarkInfo(name: "DataAppendDataSmallToSmall", + runFunction: run_AppendDataSmallToSmall, tags: d), + BenchmarkInfo(name: "DataAppendDataSmallToMedium", + runFunction: run_AppendDataSmallToMedium, tags: d), + BenchmarkInfo(name: "DataAppendDataSmallToLarge", + runFunction: run_AppendDataSmallToLarge, tags: d), + BenchmarkInfo(name: "DataAppendDataMediumToSmall", + runFunction: run_AppendDataMediumToSmall, tags: d), + BenchmarkInfo(name: "DataAppendDataMediumToMedium", + runFunction: run_AppendDataMediumToMedium, tags: d), + BenchmarkInfo(name: "DataAppendDataMediumToLarge", + runFunction: run_AppendDataMediumToLarge, tags: skip), + BenchmarkInfo(name: "DataAppendDataLargeToSmall", + runFunction: run_AppendDataLargeToSmall, tags: d), + BenchmarkInfo(name: "DataAppendDataLargeToMedium", + runFunction: run_AppendDataLargeToMedium, tags: d), + BenchmarkInfo(name: "DataAppendDataLargeToLarge", + runFunction: run_AppendDataLargeToLarge, tags: skip), + + BenchmarkInfo(name: "DataToStringEmpty", + runFunction: run_DataToStringEmpty, tags: d, legacyFactor: 50), + BenchmarkInfo(name: "DataToStringSmall", + runFunction: run_DataToStringSmall, tags: d, legacyFactor: 50), + BenchmarkInfo(name: "DataToStringMedium", + runFunction: run_DataToStringMedium, tags: d, legacyFactor: 50), + + BenchmarkInfo(name: "StringToDataEmpty", + runFunction: run_StringToDataEmpty, tags: d, legacyFactor: 50), + BenchmarkInfo(name: "StringToDataSmall", + runFunction: run_StringToDataSmall, tags: d, legacyFactor: 50), + BenchmarkInfo(name: "StringToDataMedium", + runFunction: run_StringToDataMedium, tags: d, legacyFactor: 50), ] enum SampleKind { From 1648dcde8c792dfb4ae4ec12f685a4ac1e2a2461 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 21 Dec 2018 06:33:40 +0100 Subject: [PATCH 03/26] [Gardening] DataBenchmarks remove unused string --- benchmark/single-source/DataBenchmarks.swift | 37 +------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 7ac64a646afa8..49db744798b34 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -130,7 +130,7 @@ public let DataBenchmarks = [ runFunction: run_DataToStringSmall, tags: d, legacyFactor: 50), BenchmarkInfo(name: "DataToStringMedium", runFunction: run_DataToStringMedium, tags: d, legacyFactor: 50), - + BenchmarkInfo(name: "StringToDataEmpty", runFunction: run_StringToDataEmpty, tags: d, legacyFactor: 50), BenchmarkInfo(name: "StringToDataSmall", @@ -144,7 +144,6 @@ enum SampleKind { case medium case large case veryLarge - case string case immutableBacking } @@ -154,39 +153,6 @@ func sampleData(size: Int) -> Data { return data } -func sampleString() -> Data { - let bytes: [UInt8] = [ - 0x4c,0x6f,0x72,0x65, 0x6d,0x20,0x69,0x70, 0x73,0x75,0x6d,0x20, 0x64,0x6f,0x6c,0x6f, - 0x72,0x20,0x73,0x69, 0x74,0x20,0x61,0x6d, 0x65,0x74,0x2c,0x20, 0x63,0x6f,0x6e,0x73, - 0x65,0x63,0x74,0x65, 0x74,0x75,0x72,0x20, 0x61,0x64,0x69,0x70, 0x69,0x73,0x69,0x63, - 0x69,0x6e,0x67,0x20, 0x65,0x6c,0x69,0x74, 0x2c,0x20,0x73,0x65, 0x64,0x20,0x64,0x6f, - 0x20,0x65,0x69,0x75, 0x73,0x6d,0x6f,0x64, 0x0a,0x74,0x65,0x6d, 0x70,0x6f,0x72,0x20, - 0x69,0x6e,0x63,0x69, 0x64,0x69,0x64,0x75, 0x6e,0x74,0x20,0x75, 0x74,0x20,0x6c,0x61, - 0x62,0x6f,0x72,0x65, 0x20,0x65,0x74,0x20, 0x64,0x6f,0x6c,0x6f, 0x72,0x65,0x20,0x6d, - 0x61,0x67,0x6e,0x61, 0x20,0x61,0x6c,0x69, 0x71,0x75,0x61,0x2e, 0x20,0x55,0x74,0x20, - 0x65,0x6e,0x69,0x6d, 0x20,0x61,0x64,0x20, 0x6d,0x69,0x6e,0x69, 0x6d,0x20,0x76,0x65, - 0x6e,0x69,0x61,0x6d, 0x2c,0x0a,0x71,0x75, 0x69,0x73,0x20,0x6e, 0x6f,0x73,0x74,0x72, - 0x75,0x64,0x20,0x65, 0x78,0x65,0x72,0x63, 0x69,0x74,0x61,0x74, 0x69,0x6f,0x6e,0x20, - 0x75,0x6c,0x6c,0x61, 0x6d,0x63,0x6f,0x20, 0x6c,0x61,0x62,0x6f, 0x72,0x69,0x73,0x20, - 0x6e,0x69,0x73,0x69, 0x20,0x75,0x74,0x20, 0x61,0x6c,0x69,0x71, 0x75,0x69,0x70,0x20, - 0x65,0x78,0x20,0x65, 0x61,0x20,0x63,0x6f, 0x6d,0x6d,0x6f,0x64, 0x6f,0x0a,0x63,0x6f, - 0x6e,0x73,0x65,0x71, 0x75,0x61,0x74,0x2e, 0x20,0x44,0x75,0x69, 0x73,0x20,0x61,0x75, - 0x74,0x65,0x20,0x69, 0x72,0x75,0x72,0x65, 0x20,0x64,0x6f,0x6c, 0x6f,0x72,0x20,0x69, - 0x6e,0x20,0x72,0x65, 0x70,0x72,0x65,0x68, 0x65,0x6e,0x64,0x65, 0x72,0x69,0x74,0x20, - 0x69,0x6e,0x20,0x76, 0x6f,0x6c,0x75,0x70, 0x74,0x61,0x74,0x65, 0x20,0x76,0x65,0x6c, - 0x69,0x74,0x20,0x65, 0x73,0x73,0x65,0x0a, 0x63,0x69,0x6c,0x6c, 0x75,0x6d,0x20,0x64, - 0x6f,0x6c,0x6f,0x72, 0x65,0x20,0x65,0x75, 0x20,0x66,0x75,0x67, 0x69,0x61,0x74,0x20, - 0x6e,0x75,0x6c,0x6c, 0x61,0x20,0x70,0x61, 0x72,0x69,0x61,0x74, 0x75,0x72,0x2e,0x20, - 0x45,0x78,0x63,0x65, 0x70,0x74,0x65,0x75, 0x72,0x20,0x73,0x69, 0x6e,0x74,0x20,0x6f, - 0x63,0x63,0x61,0x65, 0x63,0x61,0x74,0x20, 0x63,0x75,0x70,0x69, 0x64,0x61,0x74,0x61, - 0x74,0x20,0x6e,0x6f, 0x6e,0x0a,0x70,0x72, 0x6f,0x69,0x64,0x65, 0x6e,0x74,0x2c,0x20, - 0x73,0x75,0x6e,0x74, 0x20,0x69,0x6e,0x20, 0x63,0x75,0x6c,0x70, 0x61,0x20,0x71,0x75, - 0x69,0x20,0x6f,0x66, 0x66,0x69,0x63,0x69, 0x61,0x20,0x64,0x65, 0x73,0x65,0x72,0x75, - 0x6e,0x74,0x20,0x6d, 0x6f,0x6c,0x6c,0x69, 0x74,0x20,0x61,0x6e, 0x69,0x6d,0x20,0x69, - 0x64,0x20,0x65,0x73, 0x74,0x20,0x6c,0x61, 0x62,0x6f,0x72,0x75, 0x6d,0x2e,0x0a,0x00] - return Data(bytes: bytes) -} - #if os(Linux) import Glibc #endif @@ -233,7 +199,6 @@ func sampleData(_ type: SampleKind) -> Data { case .medium: return sampleData(size: 1033) case .large: return sampleData(size: 40980) case .veryLarge: return sampleData(size: 1024 * 1024 * 1024 + 128) - case .string: return sampleString() case .immutableBacking: return sampleBridgedNSData() } From 1ad6a9a875b733683150262445e83975b3f11443 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Thu, 20 Dec 2018 22:52:02 +0100 Subject: [PATCH 04/26] =?UTF-8?q?[benchmark]=20Fix:=20Don=E2=80=99t=20benc?= =?UTF-8?q?hmark=20arc4random=5Fbuf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit arc4random_buf was dominating the creation time. We don’t need trully random data. Anything that quickly fills the buffer will do. --- benchmark/single-source/DataBenchmarks.swift | 44 ++++++-------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 49db744798b34..7138fc46d5f51 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -147,47 +147,27 @@ enum SampleKind { case immutableBacking } -func sampleData(size: Int) -> Data { - var data = Data(count: size) - data.withUnsafeMutableBytes { getRandomBuf(baseAddress: $0, count: size) } - return data -} - -#if os(Linux) -import Glibc -#endif - -@inline(__always) -func getRandomBuf(_ arg: UnsafeMutableBufferPointer) { - #if os(Linux) - let fd = open("/dev/urandom", O_RDONLY) - defer { if (fd >= 0) { close(fd) } } - if fd >= 0 { - read(fd, arg.baseAddress, arg.count) +func fillBuffer(_ buffer: UnsafeMutableBufferPointer) { + for i in buffer.indices { + buffer[i] = UInt8(truncatingIfNeeded: i) } - #else - arc4random_buf(arg.baseAddress, arg.count) - #endif } -@inline(__always) -func getRandomBuf(baseAddress: UnsafeMutablePointer, count: Int) { - #if os(Linux) - let fd = open("/dev/urandom", O_RDONLY) - defer { if (fd >= 0) { close(fd) } } - if fd >= 0 { - read(fd, baseAddress, count) +func sampleData(size: Int) -> Data { + var data = Data(count: size) + data.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer) -> () in + for i in 0.. Data { let count = 1033 var bytes = [UInt8](repeating: 0, count: count) bytes.withUnsafeMutableBufferPointer { - getRandomBuf($0) + fillBuffer($0) } let data = NSData(bytes: bytes, length: count) return Data(referencing: data) @@ -244,7 +224,7 @@ func benchmark_AppendBytes(_ N: Int, _ count: Int, _ data_: Data) { func benchmark_AppendArray(_ N: Int, _ count: Int, _ data_: Data) { var bytes = [UInt8](repeating: 0, count: count) bytes.withUnsafeMutableBufferPointer { - getRandomBuf($0) + fillBuffer($0) } for _ in 0..<10000*N { var data = data_ From 752310c4989d53dc2fa4fd03392b7ff751a57b07 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 10:47:15 +0100 Subject: [PATCH 05/26] [benchmark] Data workload variables For extracting setup overhead. Even the `large` sample Data is only 40KB, we can afford this to be static constant. --- benchmark/single-source/DataBenchmarks.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 7138fc46d5f51..4f3a971af1026 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -139,6 +139,10 @@ public let DataBenchmarks = [ runFunction: run_StringToDataMedium, tags: d, legacyFactor: 50), ] +let small = sampleData(.small) +let medium = sampleData(.medium) +let large = sampleData(.large) + enum SampleKind { case small case medium From 34121a9ed34f0c81c75d992b0b7ad92d0a3a3d6c Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 20:10:00 +0100 Subject: [PATCH 06/26] [benchmark] Remove incorrect `Large` variants Removed the disabled Large variants (tagged `.skip`). We might re-introduce proper benchmarks for the `LargeSlice` implementation later, but for **that** the capacity has to be at least Int32.max (i.e. over 2GB). The `sampleData(.veryLarge)` was only 1GB. --- benchmark/single-source/DataBenchmarks.swift | 54 -------------------- 1 file changed, 54 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 4f3a971af1026..257cef356b502 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -23,8 +23,6 @@ public let DataBenchmarks = [ runFunction: run_createSmall, tags: d), BenchmarkInfo(name: "DataCreateMedium", runFunction: run_createMedium, tags: d), - BenchmarkInfo(name: "DataCreateLarge", - runFunction: run_createLarge, tags: skip), BenchmarkInfo(name: "DataCreateEmptyArray", runFunction: run_createEmptyArray, tags: d), @@ -37,15 +35,11 @@ public let DataBenchmarks = [ runFunction: run_SubscriptSmall, tags: d), BenchmarkInfo(name: "DataSubscriptMedium", runFunction: run_SubscriptMedium, tags: d), - BenchmarkInfo(name: "DataSubscriptLarge", - runFunction: run_SubscriptLarge, tags: skip), BenchmarkInfo(name: "DataCountSmall", runFunction: run_CountSmall, tags: d), BenchmarkInfo(name: "DataCountMedium", runFunction: run_CountMedium, tags: d), - BenchmarkInfo(name: "DataCountLarge", - runFunction: run_CountLarge, tags: skip), BenchmarkInfo(name: "DataSetCountSmall", runFunction: run_SetCountSmall, tags: d), @@ -58,15 +52,11 @@ public let DataBenchmarks = [ runFunction: run_AccessBytesSmall, tags: d), BenchmarkInfo(name: "DataAccessBytesMedium", runFunction: run_AccessBytesMedium, tags: d), - BenchmarkInfo(name: "DataAccessBytesLarge", - runFunction: run_AccessBytesLarge, tags: skip), BenchmarkInfo(name: "DataMutateBytesSmall", runFunction: run_MutateBytesSmall, tags: d), BenchmarkInfo(name: "DataMutateBytesMedium", runFunction: run_MutateBytesMedium, tags: d), - BenchmarkInfo(name: "DataMutateBytesLarge", - runFunction: run_MutateBytesLarge, tags: skip), BenchmarkInfo(name: "DataCopyBytesSmall", runFunction: run_CopyBytesSmall, tags: d), @@ -79,8 +69,6 @@ public let DataBenchmarks = [ runFunction: run_AppendBytesSmall, tags: d), BenchmarkInfo(name: "DataAppendBytesMedium", runFunction: run_AppendBytesMedium, tags: d), - BenchmarkInfo(name: "DataAppendBytesLarge", - runFunction: run_AppendBytesLarge, tags: skip), BenchmarkInfo(name: "DataAppendArray", runFunction: run_AppendArray, tags: d), @@ -293,16 +281,6 @@ public func run_SubscriptMedium(_ N: Int) { } } -@inline(never) -public func run_SubscriptLarge(_ N: Int) { - let data = sampleData(.veryLarge) - let index = 521 - for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call - blackHole(data[index]) - } -} - @inline(never) public func run_CountSmall(_ N: Int) { let data = sampleData(.small) @@ -321,15 +299,6 @@ public func run_CountMedium(_ N: Int) { } } -@inline(never) -public func run_CountLarge(_ N: Int) { - let data = sampleData(.veryLarge) - for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call - blackHole(data.count) - } -} - @inline(never) public func run_SetCountSmall(_ N: Int) { var data = sampleData(.small) @@ -376,12 +345,6 @@ public func run_AccessBytesMedium(_ N: Int) { benchmark_AccessBytes(N, data) } -@inline(never) -public func run_AccessBytesLarge(_ N: Int) { - let data = sampleData(.veryLarge) - benchmark_AccessBytes(N, data) -} - @inline(never) public func run_MutateBytesSmall(_ N: Int) { let data = sampleData(.small) @@ -394,12 +357,6 @@ public func run_MutateBytesMedium(_ N: Int) { benchmark_MutateBytes(N, data) } -@inline(never) -public func run_MutateBytesLarge(_ N: Int) { - let data = sampleData(.veryLarge) - benchmark_MutateBytes(N, data) -} - @inline(never) public func run_CopyBytesSmall(_ N: Int) { let data = sampleData(.small) @@ -430,12 +387,6 @@ public func run_AppendBytesMedium(_ N: Int) { benchmark_AppendBytes(N, 809, data) } -@inline(never) -public func run_AppendBytesLarge(_ N: Int) { - let data = sampleData(.veryLarge) - benchmark_AppendBytes(N, 809, data) -} - @inline(never) public func run_AppendArray(_ N: Int) { let data = sampleData(.medium) @@ -589,11 +540,6 @@ public func run_createMedium(_ N: Int) { } } -@inline(never) -public func run_createLarge(_ N: Int) { - blackHole(sampleData(.veryLarge)) -} - @inline(never) public func run_createEmptyArray(_ N: Int) { for _ in 0..<100000 * N { From 1d626fa1076f1a03e06c15bccb0fbec2bd177f8e Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 20:15:26 +0100 Subject: [PATCH 07/26] [benchmark] DataCount refactored Refactored to use shared test method and inlined runFunctions. Extracted setup overhead. `blackHole` is ubiquitous in SBS, no need to state the obvious. --- benchmark/single-source/DataBenchmarks.swift | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 257cef356b502..4c540d7c9ff17 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -37,9 +37,9 @@ public let DataBenchmarks = [ runFunction: run_SubscriptMedium, tags: d), BenchmarkInfo(name: "DataCountSmall", - runFunction: run_CountSmall, tags: d), + runFunction: { count($0, data: small) }, tags: d), BenchmarkInfo(name: "DataCountMedium", - runFunction: run_CountMedium, tags: d), + runFunction: { count($0, data: medium) }, tags: d), BenchmarkInfo(name: "DataSetCountSmall", runFunction: run_SetCountSmall, tags: d), @@ -282,19 +282,8 @@ public func run_SubscriptMedium(_ N: Int) { } @inline(never) -public func run_CountSmall(_ N: Int) { - let data = sampleData(.small) - for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call - blackHole(data.count) - } -} - -@inline(never) -public func run_CountMedium(_ N: Int) { - let data = sampleData(.medium) +public func count(_ N: Int, data: Data) { for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call blackHole(data.count) } } From 6146fd0f6d0b83620776f45acb22a3e05b0372b2 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 21:33:07 +0100 Subject: [PATCH 08/26] [benchmark] DataSubscript refactored Refactored to use inlined runFunctions. Extracted setup overhead. --- benchmark/single-source/DataBenchmarks.swift | 24 ++------------------ 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 4c540d7c9ff17..e573b8aecbc0e 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -32,9 +32,9 @@ public let DataBenchmarks = [ runFunction: run_createMediumArray, tags: d), BenchmarkInfo(name: "DataSubscriptSmall", - runFunction: run_SubscriptSmall, tags: d), + runFunction: { for _ in 0..<$0*10_000 { blackHole(small[1]) } }, tags: d), BenchmarkInfo(name: "DataSubscriptMedium", - runFunction: run_SubscriptMedium, tags: d), + runFunction: { for _ in 0..<$0*10_000 { blackHole(medium[521]) } }, tags: d), BenchmarkInfo(name: "DataCountSmall", runFunction: { count($0, data: small) }, tags: d), @@ -261,26 +261,6 @@ func benchmark_AppendData(_ N: Int, _ lhs: Data, _ rhs: Data) { } } -@inline(never) -public func run_SubscriptSmall(_ N: Int) { - let data = sampleData(.small) - let index = 1 - for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call - blackHole(data[index]) - } -} - -@inline(never) -public func run_SubscriptMedium(_ N: Int) { - let data = sampleData(.medium) - let index = 521 - for _ in 0..<10000*N { - // Ensure that the compiler does not optimize away this call - blackHole(data[index]) - } -} - @inline(never) public func count(_ N: Int, data: Data) { for _ in 0..<10000*N { From 11b84e56b150230ad9681a570db67f9e05a2ef2c Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 20:46:18 +0100 Subject: [PATCH 09/26] [benchmark] DataSetCount refactored Refactored to use shared test method and inlined runFunctions. Extracted setup overhead. Removed `Large` variant, as it was testing the same underlying implementation as `Medium`. --- benchmark/single-source/DataBenchmarks.swift | 38 ++++---------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index e573b8aecbc0e..939940ba22905 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -42,11 +42,9 @@ public let DataBenchmarks = [ runFunction: { count($0, data: medium) }, tags: d), BenchmarkInfo(name: "DataSetCountSmall", - runFunction: run_SetCountSmall, tags: d), + runFunction: { setCount($0, data: small, extra: 3) }, tags: d), BenchmarkInfo(name: "DataSetCountMedium", - runFunction: run_SetCountMedium, tags: d), - BenchmarkInfo(name: "DataSetCountLarge", - runFunction: run_SetCountLarge, tags: skip), + runFunction: { setCount($0, data: medium, extra: 100) }, tags: d), BenchmarkInfo(name: "DataAccessBytesSmall", runFunction: run_AccessBytesSmall, tags: d), @@ -269,35 +267,13 @@ public func count(_ N: Int, data: Data) { } @inline(never) -public func run_SetCountSmall(_ N: Int) { - var data = sampleData(.small) - let count = data.count + 3 +public func setCount(_ N: Int, data: Data, extra: Int) { + var copy = data + let count = data.count + extra let orig = data.count for _ in 0..<10000*N { - data.count = count - data.count = orig - } -} - -@inline(never) -public func run_SetCountMedium(_ N: Int) { - var data = sampleData(.medium) - let count = data.count + 100 - let orig = data.count - for _ in 0..<10000*N { - data.count = count - data.count = orig - } -} - -@inline(never) -public func run_SetCountLarge(_ N: Int) { - var data = sampleData(.large) - let count = data.count + 100 - let orig = data.count - for _ in 0..<10000*N { - data.count = count - data.count = orig + copy.count = count + copy.count = orig } } From c272e921f637e80d83d766b7849f2a1a76d34107 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 20:27:07 +0100 Subject: [PATCH 10/26] [benchmark] DataAccessBytes refactored Refactored to use shared test method and inlined runFunctions. Extracted setup overhead. `blackHole` is ubiquitous in SBS, no need to state the obvious. --- benchmark/single-source/DataBenchmarks.swift | 21 ++++---------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 939940ba22905..cf4f01694b2b7 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -47,9 +47,9 @@ public let DataBenchmarks = [ runFunction: { setCount($0, data: medium, extra: 100) }, tags: d), BenchmarkInfo(name: "DataAccessBytesSmall", - runFunction: run_AccessBytesSmall, tags: d), + runFunction: { withUnsafeBytes($0, data: small) }, tags: d), BenchmarkInfo(name: "DataAccessBytesMedium", - runFunction: run_AccessBytesMedium, tags: d), + runFunction: { withUnsafeBytes($0, data: medium) }, tags: d), BenchmarkInfo(name: "DataMutateBytesSmall", runFunction: run_MutateBytesSmall, tags: d), @@ -174,10 +174,10 @@ func sampleData(_ type: SampleKind) -> Data { } -func benchmark_AccessBytes(_ N: Int, _ data: Data) { +@inline(never) +func withUnsafeBytes(_ N: Int, data: Data) { for _ in 0..<10000*N { data.withUnsafeBytes { (ptr: UnsafePointer) in - // Ensure that the compiler does not optimize away this call blackHole(ptr.pointee) } } @@ -277,19 +277,6 @@ public func setCount(_ N: Int, data: Data, extra: Int) { } } -@inline(never) -public func run_AccessBytesSmall(_ N: Int) { - let data = sampleData(.small) - benchmark_AccessBytes(N, data) -} - - -@inline(never) -public func run_AccessBytesMedium(_ N: Int) { - let data = sampleData(.medium) - benchmark_AccessBytes(N, data) -} - @inline(never) public func run_MutateBytesSmall(_ N: Int) { let data = sampleData(.small) From d60dbe58e625f2376efcc9cd3616ee26025e77ee Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 20:28:55 +0100 Subject: [PATCH 11/26] [benchmark] DataMutateBytes refactored Refactored to use shared test method and inlined runFunctions. Extracted setup overhead. --- benchmark/single-source/DataBenchmarks.swift | 23 +++++--------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index cf4f01694b2b7..7d2afe478de2b 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -52,9 +52,9 @@ public let DataBenchmarks = [ runFunction: { withUnsafeBytes($0, data: medium) }, tags: d), BenchmarkInfo(name: "DataMutateBytesSmall", - runFunction: run_MutateBytesSmall, tags: d), + runFunction: { withUnsafeMutableBytes($0, data: small) }, tags: d), BenchmarkInfo(name: "DataMutateBytesMedium", - runFunction: run_MutateBytesMedium, tags: d), + runFunction: { withUnsafeMutableBytes($0, data: medium) }, tags: d), BenchmarkInfo(name: "DataCopyBytesSmall", runFunction: run_CopyBytesSmall, tags: d), @@ -183,10 +183,11 @@ func withUnsafeBytes(_ N: Int, data: Data) { } } -func benchmark_MutateBytes(_ N: Int, _ data_: Data) { +@inline(never) +func withUnsafeMutableBytes(_ N: Int, data: Data) { for _ in 0..<10000*N { - var data = data_ - data.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer) in + var copy = data + copy.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer) in // Mutate a byte ptr.pointee = 42 } @@ -277,18 +278,6 @@ public func setCount(_ N: Int, data: Data, extra: Int) { } } -@inline(never) -public func run_MutateBytesSmall(_ N: Int) { - let data = sampleData(.small) - benchmark_MutateBytes(N, data) -} - -@inline(never) -public func run_MutateBytesMedium(_ N: Int) { - let data = sampleData(.medium) - benchmark_MutateBytes(N, data) -} - @inline(never) public func run_CopyBytesSmall(_ N: Int) { let data = sampleData(.small) From 8e2f000a58e5efe7ec64f91126203e93177faded Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 20:57:31 +0100 Subject: [PATCH 12/26] [benchmark] DataCopyBytes refactored Refactored to use shared test method and inlined runFunctions. Extracted setup overhead. Removed `Large` variant, as it was testing the same underlying implementation as `Medium`. --- benchmark/single-source/DataBenchmarks.swift | 27 +++----------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 7d2afe478de2b..cc26f9c786c4a 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -57,11 +57,9 @@ public let DataBenchmarks = [ runFunction: { withUnsafeMutableBytes($0, data: medium) }, tags: d), BenchmarkInfo(name: "DataCopyBytesSmall", - runFunction: run_CopyBytesSmall, tags: d), + runFunction: { copyBytes($0, data: small) }, tags: d), BenchmarkInfo(name: "DataCopyBytesMedium", - runFunction: run_CopyBytesMedium, tags: d), - BenchmarkInfo(name: "DataCopyBytesLarge", - runFunction: run_CopyBytesLarge, tags: skip), + runFunction: { copyBytes($0, data: medium) }, tags: d), BenchmarkInfo(name: "DataAppendBytesSmall", runFunction: run_AppendBytesSmall, tags: d), @@ -194,7 +192,8 @@ func withUnsafeMutableBytes(_ N: Int, data: Data) { } } -func benchmark_CopyBytes(_ N: Int, _ data: Data) { +@inline(never) +func copyBytes(_ N: Int, data: Data) { let amount = data.count var buffer = UnsafeMutablePointer.allocate(capacity: amount) defer { buffer.deallocate() } @@ -278,24 +277,6 @@ public func setCount(_ N: Int, data: Data, extra: Int) { } } -@inline(never) -public func run_CopyBytesSmall(_ N: Int) { - let data = sampleData(.small) - benchmark_CopyBytes(N, data) -} - -@inline(never) -public func run_CopyBytesMedium(_ N: Int) { - let data = sampleData(.medium) - benchmark_CopyBytes(N, data) -} - -@inline(never) -public func run_CopyBytesLarge(_ N: Int) { - let data = sampleData(.large) - benchmark_CopyBytes(N, data) -} - @inline(never) public func run_AppendBytesSmall(_ N: Int) { let data = sampleData(.small) From b55997a45be77e7c45c3d28fe097e5043657e94a Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 20:30:52 +0100 Subject: [PATCH 13/26] [benchmark] DataAppendBytes refactored Refactored to use shared test method and inlined runFunctions. Extracted setup overhead. --- benchmark/single-source/DataBenchmarks.swift | 23 +++++--------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index cc26f9c786c4a..74e8544603d02 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -62,9 +62,9 @@ public let DataBenchmarks = [ runFunction: { copyBytes($0, data: medium) }, tags: d), BenchmarkInfo(name: "DataAppendBytesSmall", - runFunction: run_AppendBytesSmall, tags: d), + runFunction: { append($0, bytes: 3, to: small) }, tags: d), BenchmarkInfo(name: "DataAppendBytesMedium", - runFunction: run_AppendBytesMedium, tags: d), + runFunction: { append($0, bytes: 809, to: medium) }, tags: d), BenchmarkInfo(name: "DataAppendArray", runFunction: run_AppendArray, tags: d), @@ -202,12 +202,13 @@ func copyBytes(_ N: Int, data: Data) { } } -func benchmark_AppendBytes(_ N: Int, _ count: Int, _ data_: Data) { +@inline(never) +func append(_ N: Int, bytes count: Int, to data: Data) { let bytes = malloc(count).assumingMemoryBound(to: UInt8.self) defer { free(bytes) } for _ in 0..<10000*N { - var data = data_ - data.append(bytes, count: count) + var copy = data + copy.append(bytes, count: count) } } @@ -277,18 +278,6 @@ public func setCount(_ N: Int, data: Data, extra: Int) { } } -@inline(never) -public func run_AppendBytesSmall(_ N: Int) { - let data = sampleData(.small) - benchmark_AppendBytes(N, 3, data) -} - -@inline(never) -public func run_AppendBytesMedium(_ N: Int) { - let data = sampleData(.medium) - benchmark_AppendBytes(N, 809, data) -} - @inline(never) public func run_AppendArray(_ N: Int) { let data = sampleData(.medium) From c8da0a9f85342f0ccde082538ba47f573398dea4 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 20:31:58 +0100 Subject: [PATCH 14/26] [benchmark] DataCreateArray refactored Refactored to use inlined runFunctions. --- benchmark/single-source/DataBenchmarks.swift | 33 ++++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 74e8544603d02..1e221b3e30a2c 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -25,11 +25,17 @@ public let DataBenchmarks = [ runFunction: run_createMedium, tags: d), BenchmarkInfo(name: "DataCreateEmptyArray", - runFunction: run_createEmptyArray, tags: d), + runFunction: { for _ in 0..<$0*100_000 { blackHole(Data([])) } }, tags: d), BenchmarkInfo(name: "DataCreateSmallArray", - runFunction: run_createSmallArray, tags: d), + runFunction: { for _ in 0..<$0*100_000 { blackHole(Data( + [0, 1, 2, 3, 4, 5, 6])) } }, tags: d), BenchmarkInfo(name: "DataCreateMediumArray", - runFunction: run_createMediumArray, tags: d), + runFunction: { for _ in 0..<$0*10_000 { blackHole(Data([ + 0, 1, 2, 3, 4, 5, 6, + 0, 1, 2, 3, 4, 5, 6, + 0, 1, 2, 3, 4, 5, 6, + 0, 1, 2, 3, 4, 5, 6, + ])) } }, tags: d), BenchmarkInfo(name: "DataSubscriptSmall", runFunction: { for _ in 0..<$0*10_000 { blackHole(small[1]) } }, tags: d), @@ -431,27 +437,6 @@ public func run_createMedium(_ N: Int) { } } -@inline(never) -public func run_createEmptyArray(_ N: Int) { - for _ in 0..<100000 * N { - blackHole(Data([])) - } -} - -@inline(never) -public func run_createSmallArray(_ N: Int) { - for _ in 0..<100000 * N { - blackHole(Data([0, 1, 2, 3, 4, 5, 6])) - } -} - -@inline(never) -public func run_createMediumArray(_ N: Int) { - for _ in 0..<10000 * N { - blackHole(Data([0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6])) - } -} - @inline(never) public func run_DataToStringEmpty(_ N: Int) { let d = Data() From 21baf467bbd78db0b628bd5078f12dbb2e6b091f Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 20:33:25 +0100 Subject: [PATCH 15/26] [benchmark] DataCreate refactored Refactored to use inlined runFunctions. --- benchmark/single-source/DataBenchmarks.swift | 29 ++++---------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 1e221b3e30a2c..f1eb0164779a5 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -18,11 +18,13 @@ let skip: [BenchmarkCategory] = [.validation, .api, .Data, .skip] public let DataBenchmarks = [ BenchmarkInfo(name: "DataCreateEmpty", - runFunction: run_createEmpty, tags: d), + runFunction: { for _ in 0..<$0*100_000 { blackHole(Data()) } }, tags: d), BenchmarkInfo(name: "DataCreateSmall", - runFunction: run_createSmall, tags: d), + runFunction: { for _ in 0..<$0*100_000 { blackHole(sampleData(.small)) } }, + tags: d), BenchmarkInfo(name: "DataCreateMedium", - runFunction: run_createMedium, tags: d), + runFunction: { for _ in 0..<$0*10_000 { blackHole(sampleData(.medium)) } }, + tags: d), BenchmarkInfo(name: "DataCreateEmptyArray", runFunction: { for _ in 0..<$0*100_000 { blackHole(Data([])) } }, tags: d), @@ -416,27 +418,6 @@ public func run_AppendDataLargeToLarge(_ N: Int) { benchmark_AppendData(N, data, other) } -@inline(never) -public func run_createEmpty(_ N: Int) { - for _ in 0..<100000 * N { - blackHole(Data()) - } -} - -@inline(never) -public func run_createSmall(_ N: Int) { - for _ in 0..<100000 * N { - blackHole(sampleData(.small)) - } -} - -@inline(never) -public func run_createMedium(_ N: Int) { - for _ in 0..<10000 * N { - blackHole(sampleData(.medium)) - } -} - @inline(never) public func run_DataToStringEmpty(_ N: Int) { let d = Data() From e127acd2cba330d51f40a00d0baa035a339435c2 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 21:08:44 +0100 Subject: [PATCH 16/26] [benchmark] DataAppendData refactored Refactored to use shared test method and inlined runFunctions. Extracted setup overhead. Re-enabled `Large` tests errorneously disabled in #20411. --- benchmark/single-source/DataBenchmarks.swift | 90 +++----------------- 1 file changed, 14 insertions(+), 76 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index f1eb0164779a5..b11042cc2c92f 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -98,23 +98,23 @@ public let DataBenchmarks = [ runFunction: run_AppendSequence, tags: d), BenchmarkInfo(name: "DataAppendDataSmallToSmall", - runFunction: run_AppendDataSmallToSmall, tags: d), + runFunction: { append($0, data: small, to: small) }, tags: d), BenchmarkInfo(name: "DataAppendDataSmallToMedium", - runFunction: run_AppendDataSmallToMedium, tags: d), + runFunction: { append($0, data: small, to: medium) }, tags: d), BenchmarkInfo(name: "DataAppendDataSmallToLarge", - runFunction: run_AppendDataSmallToLarge, tags: d), + runFunction: { append($0, data: small, to: large) }, tags: d), BenchmarkInfo(name: "DataAppendDataMediumToSmall", - runFunction: run_AppendDataMediumToSmall, tags: d), + runFunction: { append($0, data: medium, to: small) }, tags: d), BenchmarkInfo(name: "DataAppendDataMediumToMedium", - runFunction: run_AppendDataMediumToMedium, tags: d), + runFunction: { append($0, data: medium, to: medium) }, tags: d), BenchmarkInfo(name: "DataAppendDataMediumToLarge", - runFunction: run_AppendDataMediumToLarge, tags: skip), + runFunction: { append($0, data: medium, to: large) }, tags: d), BenchmarkInfo(name: "DataAppendDataLargeToSmall", - runFunction: run_AppendDataLargeToSmall, tags: d), + runFunction: { append($0, data: large, to: small) }, tags: d), BenchmarkInfo(name: "DataAppendDataLargeToMedium", - runFunction: run_AppendDataLargeToMedium, tags: d), + runFunction: { append($0, data: large, to: medium) }, tags: d), BenchmarkInfo(name: "DataAppendDataLargeToLarge", - runFunction: run_AppendDataLargeToLarge, tags: skip), + runFunction: { append($0, data: large, to: large) }, tags: d), BenchmarkInfo(name: "DataToStringEmpty", runFunction: run_DataToStringEmpty, tags: d, legacyFactor: 50), @@ -260,11 +260,12 @@ func benchmark_ReplaceBuffer(_ N: Int, _ range: Range, _ data_: Data } } -func benchmark_AppendData(_ N: Int, _ lhs: Data, _ rhs: Data) { - var data = lhs +@inline(never) +func append(_ N: Int, data: Data, to target: Data) { + var copy: Data for _ in 0..<10000*N { - data = lhs - data.append(rhs) + copy = target + copy.append(data) } } @@ -355,69 +356,6 @@ public func run_AppendSequence(_ N: Int) { benchmark_AppendSequence(N, 809, data) } -@inline(never) -public func run_AppendDataSmallToSmall(_ N: Int) { - let data = sampleData(.small) - let other = sampleData(.small) - benchmark_AppendData(N, data, other) -} - -@inline(never) -public func run_AppendDataSmallToMedium(_ N: Int) { - let data = sampleData(.medium) - let other = sampleData(.small) - benchmark_AppendData(N, data, other) -} - -@inline(never) -public func run_AppendDataSmallToLarge(_ N: Int) { - let data = sampleData(.large) - let other = sampleData(.small) - benchmark_AppendData(N, data, other) -} - -@inline(never) -public func run_AppendDataMediumToSmall(_ N: Int) { - let data = sampleData(.small) - let other = sampleData(.medium) - benchmark_AppendData(N, data, other) -} - -@inline(never) -public func run_AppendDataMediumToMedium(_ N: Int) { - let data = sampleData(.medium) - let other = sampleData(.medium) - benchmark_AppendData(N, data, other) -} - -@inline(never) -public func run_AppendDataMediumToLarge(_ N: Int) { - let data = sampleData(.large) - let other = sampleData(.medium) - benchmark_AppendData(N, data, other) -} - -@inline(never) -public func run_AppendDataLargeToSmall(_ N: Int) { - let data = sampleData(.small) - let other = sampleData(.large) - benchmark_AppendData(N, data, other) -} - -@inline(never) -public func run_AppendDataLargeToMedium(_ N: Int) { - let data = sampleData(.medium) - let other = sampleData(.large) - benchmark_AppendData(N, data, other) -} - -@inline(never) -public func run_AppendDataLargeToLarge(_ N: Int) { - let data = sampleData(.large) - let other = sampleData(.large) - benchmark_AppendData(N, data, other) -} - @inline(never) public func run_DataToStringEmpty(_ N: Int) { let d = Data() From f239f1940bfb649009868eda3ea6c65715d7477c Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 21 Dec 2018 12:30:57 +0100 Subject: [PATCH 17/26] [benchmark] DataAppendArray refactored Refactored to use shareable test method and inlined runFunction. --- benchmark/single-source/DataBenchmarks.swift | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index b11042cc2c92f..25665abb6719f 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -75,7 +75,7 @@ public let DataBenchmarks = [ runFunction: { append($0, bytes: 809, to: medium) }, tags: d), BenchmarkInfo(name: "DataAppendArray", - runFunction: run_AppendArray, tags: d), + runFunction: { append($0, arraySize: 809, to: medium) }, tags: d), BenchmarkInfo(name: "DataReset", runFunction: run_Reset, tags: d), @@ -220,14 +220,15 @@ func append(_ N: Int, bytes count: Int, to data: Data) { } } -func benchmark_AppendArray(_ N: Int, _ count: Int, _ data_: Data) { - var bytes = [UInt8](repeating: 0, count: count) +@inline(never) +func append(_ N: Int, arraySize: Int, to data: Data) { + var bytes = [UInt8](repeating: 0, count: arraySize) bytes.withUnsafeMutableBufferPointer { fillBuffer($0) } for _ in 0..<10000*N { - var data = data_ - data.append(contentsOf: bytes) + var copy = data + copy.append(contentsOf: bytes) } } @@ -287,12 +288,6 @@ public func setCount(_ N: Int, data: Data, extra: Int) { } } -@inline(never) -public func run_AppendArray(_ N: Int) { - let data = sampleData(.medium) - benchmark_AppendArray(N, 809, data) -} - @inline(never) public func run_Reset(_ N: Int) { let data = sampleData(.medium) From 661a4c64befe17d24ece0709b07d1ccc92bf2eb0 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 10:29:41 +0100 Subject: [PATCH 18/26] [benchmark] DataAppendSequence refactored Refactored to use shareable test method and inlined runFunction. --- benchmark/single-source/DataBenchmarks.swift | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 25665abb6719f..4550bf673b5d4 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -95,7 +95,7 @@ public let DataBenchmarks = [ runFunction: run_ReplaceLargeBuffer, tags: skip), BenchmarkInfo(name: "DataAppendSequence", - runFunction: run_AppendSequence, tags: d), + runFunction: { append($0, sequenceLength: 809, to: medium) }, tags: d), BenchmarkInfo(name: "DataAppendDataSmallToSmall", runFunction: { append($0, data: small, to: small) }, tags: d), @@ -232,11 +232,12 @@ func append(_ N: Int, arraySize: Int, to data: Data) { } } -func benchmark_AppendSequence(_ N: Int, _ count: Int, _ data_: Data) { - let bytes = repeatElement(UInt8(0xA0), count: count) +@inline(never) +func append(_ N: Int, sequenceLength: Int, to data: Data) { + let bytes = repeatElement(UInt8(0xA0), count: sequenceLength) for _ in 0..<10000*N { - var data = data_ - data.append(contentsOf: bytes) + var copy = data + copy.append(contentsOf: bytes) } } @@ -345,12 +346,6 @@ public func run_ReplaceLargeBuffer(_ N: Int) { } } -@inline(never) -public func run_AppendSequence(_ N: Int) { - let data = sampleData(.medium) - benchmark_AppendSequence(N, 809, data) -} - @inline(never) public func run_DataToStringEmpty(_ N: Int) { let d = Data() From a9d9fefdfeea1a229cab5293dd8a0dd563fe517d Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 21 Dec 2018 13:29:46 +0100 Subject: [PATCH 19/26] [benchmark] DataReset refactored Refactored to use shareable test method and inlined runFunction. --- benchmark/single-source/DataBenchmarks.swift | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 4550bf673b5d4..fbbdf493f97cd 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -78,7 +78,7 @@ public let DataBenchmarks = [ runFunction: { append($0, arraySize: 809, to: medium) }, tags: d), BenchmarkInfo(name: "DataReset", - runFunction: run_Reset, tags: d), + runFunction: { resetBytes($0, in: 431..<809, data: medium) }, tags: d), BenchmarkInfo(name: "DataReplaceSmall", runFunction: run_ReplaceSmall, tags: d), @@ -241,10 +241,11 @@ func append(_ N: Int, sequenceLength: Int, to data: Data) { } } -func benchmark_Reset(_ N: Int, _ range: Range, _ data_: Data) { +@inline(never) +func resetBytes(_ N: Int, in range: Range, data: Data) { for _ in 0..<10000*N { - var data = data_ - data.resetBytes(in: range) + var copy = data + copy.resetBytes(in: range) } } @@ -289,12 +290,6 @@ public func setCount(_ N: Int, data: Data, extra: Int) { } } -@inline(never) -public func run_Reset(_ N: Int) { - let data = sampleData(.medium) - benchmark_Reset(N, 431..<809, data) -} - @inline(never) public func run_ReplaceSmall(_ N: Int) { let data = sampleData(.medium) From 5c503c8b5d952f039c1dce9509b9ea69c16063dc Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 21 Dec 2018 13:54:34 +0100 Subject: [PATCH 20/26] [benchmark] DataReplace refactored Refactored to use shared test method and inlined runFunctions. --- benchmark/single-source/DataBenchmarks.swift | 45 +++++++------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index fbbdf493f97cd..96f8961b9de07 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -80,12 +80,12 @@ public let DataBenchmarks = [ BenchmarkInfo(name: "DataReset", runFunction: { resetBytes($0, in: 431..<809, data: medium) }, tags: d), - BenchmarkInfo(name: "DataReplaceSmall", - runFunction: run_ReplaceSmall, tags: d), - BenchmarkInfo(name: "DataReplaceMedium", - runFunction: run_ReplaceMedium, tags: d), - BenchmarkInfo(name: "DataReplaceLarge", - runFunction: run_ReplaceLarge, tags: d), + BenchmarkInfo(name: "DataReplaceSmall", runFunction: { + replace($0, data: medium, subrange:431..<809, with: small) }, tags: d), + BenchmarkInfo(name: "DataReplaceMedium", runFunction: { + replace($0, data: medium, subrange:431..<809, with: medium) }, tags: d), + BenchmarkInfo(name: "DataReplaceLarge", runFunction: { + replace($0, data: medium, subrange:431..<809, with: large) }, tags: d), BenchmarkInfo(name: "DataReplaceSmallBuffer", runFunction: run_ReplaceSmallBuffer, tags: d), @@ -249,10 +249,16 @@ func resetBytes(_ N: Int, in range: Range, data: Data) { } } -func benchmark_Replace(_ N: Int, _ range: Range, _ data_: Data, _ replacement: Data) { +@inline(never) +func replace( + _ N: Int, + data: Data, + subrange range: Range, + with replacement: Data +) { for _ in 0..<10000*N { - var data = data_ - data.replaceSubrange(range, with: replacement) + var copy = data + copy.replaceSubrange(range, with: replacement) } } @@ -290,27 +296,6 @@ public func setCount(_ N: Int, data: Data, extra: Int) { } } -@inline(never) -public func run_ReplaceSmall(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.small) - benchmark_Replace(N, 431..<809, data, replacement) -} - -@inline(never) -public func run_ReplaceMedium(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.medium) - benchmark_Replace(N, 431..<809, data, replacement) -} - -@inline(never) -public func run_ReplaceLarge(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.large) - benchmark_Replace(N, 431..<809, data, replacement) -} - @inline(never) public func run_ReplaceSmallBuffer(_ N: Int) { let data = sampleData(.medium) From 0fa784fa76a5f36ed54f769d581b700b32058f89 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 22:29:41 +0100 Subject: [PATCH 21/26] [benchmark] DataReplaceBuffer refactored Refactored to use shared test method and inlined runFunctions. Re-enabled `Large` test errorneously disabled in #20411. Removed `skip` tags, as this was the last use. --- benchmark/single-source/DataBenchmarks.swift | 64 +++++++------------- 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 96f8961b9de07..ffcc1389eb4c4 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -14,7 +14,6 @@ import TestsUtils import Foundation let d: [BenchmarkCategory] = [.validation, .api, .Data] -let skip: [BenchmarkCategory] = [.validation, .api, .Data, .skip] public let DataBenchmarks = [ BenchmarkInfo(name: "DataCreateEmpty", @@ -87,12 +86,15 @@ public let DataBenchmarks = [ BenchmarkInfo(name: "DataReplaceLarge", runFunction: { replace($0, data: medium, subrange:431..<809, with: large) }, tags: d), - BenchmarkInfo(name: "DataReplaceSmallBuffer", - runFunction: run_ReplaceSmallBuffer, tags: d), - BenchmarkInfo(name: "DataReplaceMediumBuffer", - runFunction: run_ReplaceMediumBuffer, tags: d), - BenchmarkInfo(name: "DataReplaceLargeBuffer", - runFunction: run_ReplaceLargeBuffer, tags: skip), + BenchmarkInfo(name: "DataReplaceSmallBuffer", runFunction: { + replaceBuffer($0, data: medium, subrange:431..<809, with: small) }, + tags: d), + BenchmarkInfo(name: "DataReplaceMediumBuffer", runFunction: { + replaceBuffer($0, data: medium, subrange:431..<809, with: medium) }, + tags: d), + BenchmarkInfo(name: "DataReplaceLargeBuffer", runFunction: { + replaceBuffer($0, data: medium, subrange:431..<809, with: large) }, + tags: d), BenchmarkInfo(name: "DataAppendSequence", runFunction: { append($0, sequenceLength: 809, to: medium) }, tags: d), @@ -262,10 +264,20 @@ func replace( } } -func benchmark_ReplaceBuffer(_ N: Int, _ range: Range, _ data_: Data, _ replacement: UnsafeBufferPointer) { - for _ in 0..<10000*N { - var data = data_ - data.replaceSubrange(range, with: replacement) +@inline(never) +func replaceBuffer( + _ N: Int, + data: Data, + subrange range: Range, + with replacement: Data +) { + replacement.withUnsafeBytes { (bytes: UnsafePointer) in + let buffer = UnsafeBufferPointer(start: bytes, count: replacement.count) + + for _ in 0..<10000*N { + var copy = data + copy.replaceSubrange(range, with: buffer) + } } } @@ -296,36 +308,6 @@ public func setCount(_ N: Int, data: Data, extra: Int) { } } -@inline(never) -public func run_ReplaceSmallBuffer(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.small) - let sz = replacement.count - replacement.withUnsafeBytes { (ptr: UnsafePointer) in - benchmark_ReplaceBuffer(N, 431..<809, data, UnsafeBufferPointer(start: ptr, count: sz)) - } -} - -@inline(never) -public func run_ReplaceMediumBuffer(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.medium) - let sz = replacement.count - replacement.withUnsafeBytes { (ptr: UnsafePointer) in - benchmark_ReplaceBuffer(N, 431..<809, data, UnsafeBufferPointer(start: ptr, count: sz)) - } -} - -@inline(never) -public func run_ReplaceLargeBuffer(_ N: Int) { - let data = sampleData(.medium) - let replacement = sampleData(.large) - let sz = replacement.count - replacement.withUnsafeBytes { (ptr: UnsafePointer) in - benchmark_ReplaceBuffer(N, 431..<809, data, UnsafeBufferPointer(start: ptr, count: sz)) - } -} - @inline(never) public func run_DataToStringEmpty(_ N: Int) { let d = Data() From e4cdc48da5349627c0daffd2928f10409332fc82 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 10:33:09 +0100 Subject: [PATCH 22/26] [benchmark] DataToString, StringToData refactored Refactored to use shared test method and inlined runFunctions. --- benchmark/single-source/DataBenchmarks.swift | 67 +++++--------------- 1 file changed, 17 insertions(+), 50 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index ffcc1389eb4c4..9e6c869f95787 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -119,20 +119,27 @@ public let DataBenchmarks = [ runFunction: { append($0, data: large, to: large) }, tags: d), BenchmarkInfo(name: "DataToStringEmpty", - runFunction: run_DataToStringEmpty, tags: d, legacyFactor: 50), + runFunction: { string($0, from: emptyData) }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "DataToStringSmall", - runFunction: run_DataToStringSmall, tags: d, legacyFactor: 50), + runFunction: { string($0, from: smallData) }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "DataToStringMedium", - runFunction: run_DataToStringMedium, tags: d, legacyFactor: 50), + runFunction: { string($0, from: mediumData) }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "StringToDataEmpty", - runFunction: run_StringToDataEmpty, tags: d, legacyFactor: 50), + runFunction: { data($0, from: emptyString) }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "StringToDataSmall", - runFunction: run_StringToDataSmall, tags: d, legacyFactor: 50), + runFunction: { data($0, from: smallString) }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "StringToDataMedium", - runFunction: run_StringToDataMedium, tags: d, legacyFactor: 50), + runFunction: { data($0, from: mediumString) }, tags: d, legacyFactor: 50), ] +let emptyString = "" +let smallString = "\r\n" +let mediumString = "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" +let emptyData = Data() +let smallData = Data(smallString.utf8) +let mediumData = Data(mediumString.utf8) + let small = sampleData(.small) let medium = sampleData(.medium) let large = sampleData(.large) @@ -309,55 +316,15 @@ public func setCount(_ N: Int, data: Data, extra: Int) { } @inline(never) -public func run_DataToStringEmpty(_ N: Int) { - let d = Data() - for _ in 0..<200 * N { - let s = String(decoding: d, as: UTF8.self) - blackHole(s) - } -} - -@inline(never) -public func run_DataToStringSmall(_ N: Int) { - let d = Data([0x0D, 0x0A]) - for _ in 0..<200 * N { - let s = String(decoding: d, as: UTF8.self) - blackHole(s) - } -} - -@inline(never) -public func run_DataToStringMedium(_ N: Int) { - let d = Data([0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A, 0x0D, 0x0A]) - for _ in 0..<200 * N { - let s = String(decoding: d, as: UTF8.self) - blackHole(s) - } -} - -@inline(never) -public func run_StringToDataEmpty(_ N: Int) { - let s = "" - for _ in 0..<200 * N { - let d = Data(s.utf8) - blackHole(d) - } -} - -@inline(never) -public func run_StringToDataSmall(_ N: Int) { - let s = "\r\n" +public func string(_ N: Int, from data: Data) { for _ in 0..<200 * N { - let d = Data(s.utf8) - blackHole(d) + blackHole(String(decoding: data, as: UTF8.self)) } } @inline(never) -public func run_StringToDataMedium(_ N: Int) { - let s = "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" +public func data(_ N: Int, from string: String) { for _ in 0..<200 * N { - let d = Data(s.utf8) - blackHole(d) + blackHole(Data(string.utf8)) } } From 6af0eab31a1eba72e5aa0eb7ab481b4260488c60 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 22:30:29 +0100 Subject: [PATCH 23/26] [benchmark] Move loop multipliers to BenchmarkInfo --- benchmark/single-source/DataBenchmarks.swift | 121 ++++++++++--------- 1 file changed, 63 insertions(+), 58 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 9e6c869f95787..41ce320d2f0f4 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -15,23 +15,28 @@ import Foundation let d: [BenchmarkCategory] = [.validation, .api, .Data] +/// Workload scaling: Inner loop multipliers +let M = 10_000 /// default +let I = 100_000 /// Data initialization +let S = 200 /// String conversions + public let DataBenchmarks = [ BenchmarkInfo(name: "DataCreateEmpty", - runFunction: { for _ in 0..<$0*100_000 { blackHole(Data()) } }, tags: d), + runFunction: { for _ in 0..<$0*I { blackHole(Data()) } }, tags: d), BenchmarkInfo(name: "DataCreateSmall", - runFunction: { for _ in 0..<$0*100_000 { blackHole(sampleData(.small)) } }, + runFunction: { for _ in 0..<$0*I { blackHole(sampleData(.small)) } }, tags: d), BenchmarkInfo(name: "DataCreateMedium", - runFunction: { for _ in 0..<$0*10_000 { blackHole(sampleData(.medium)) } }, + runFunction: { for _ in 0..<$0*M { blackHole(sampleData(.medium)) } }, tags: d), BenchmarkInfo(name: "DataCreateEmptyArray", - runFunction: { for _ in 0..<$0*100_000 { blackHole(Data([])) } }, tags: d), + runFunction: { for _ in 0..<$0*I { blackHole(Data([])) } }, tags: d), BenchmarkInfo(name: "DataCreateSmallArray", - runFunction: { for _ in 0..<$0*100_000 { blackHole(Data( + runFunction: { for _ in 0..<$0*I { blackHole(Data( [0, 1, 2, 3, 4, 5, 6])) } }, tags: d), BenchmarkInfo(name: "DataCreateMediumArray", - runFunction: { for _ in 0..<$0*10_000 { blackHole(Data([ + runFunction: { for _ in 0..<$0*M { blackHole(Data([ 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, @@ -39,98 +44,98 @@ public let DataBenchmarks = [ ])) } }, tags: d), BenchmarkInfo(name: "DataSubscriptSmall", - runFunction: { for _ in 0..<$0*10_000 { blackHole(small[1]) } }, tags: d), + runFunction: { for _ in 0..<$0*M { blackHole(small[1]) } }, tags: d), BenchmarkInfo(name: "DataSubscriptMedium", - runFunction: { for _ in 0..<$0*10_000 { blackHole(medium[521]) } }, tags: d), + runFunction: { for _ in 0..<$0*M { blackHole(medium[521]) } }, tags: d), BenchmarkInfo(name: "DataCountSmall", - runFunction: { count($0, data: small) }, tags: d), + runFunction: { count($0*M, data: small) }, tags: d), BenchmarkInfo(name: "DataCountMedium", - runFunction: { count($0, data: medium) }, tags: d), + runFunction: { count($0*M, data: medium) }, tags: d), BenchmarkInfo(name: "DataSetCountSmall", - runFunction: { setCount($0, data: small, extra: 3) }, tags: d), + runFunction: { setCount($0*M, data: small, extra: 3) }, tags: d), BenchmarkInfo(name: "DataSetCountMedium", - runFunction: { setCount($0, data: medium, extra: 100) }, tags: d), + runFunction: { setCount($0*M, data: medium, extra: 100) }, tags: d), BenchmarkInfo(name: "DataAccessBytesSmall", - runFunction: { withUnsafeBytes($0, data: small) }, tags: d), + runFunction: { withUnsafeBytes($0*M, data: small) }, tags: d), BenchmarkInfo(name: "DataAccessBytesMedium", - runFunction: { withUnsafeBytes($0, data: medium) }, tags: d), + runFunction: { withUnsafeBytes($0*M, data: medium) }, tags: d), BenchmarkInfo(name: "DataMutateBytesSmall", - runFunction: { withUnsafeMutableBytes($0, data: small) }, tags: d), + runFunction: { withUnsafeMutableBytes($0*M, data: small) }, tags: d), BenchmarkInfo(name: "DataMutateBytesMedium", - runFunction: { withUnsafeMutableBytes($0, data: medium) }, tags: d), + runFunction: { withUnsafeMutableBytes($0*M, data: medium) }, tags: d), BenchmarkInfo(name: "DataCopyBytesSmall", - runFunction: { copyBytes($0, data: small) }, tags: d), + runFunction: { copyBytes($0*M, data: small) }, tags: d), BenchmarkInfo(name: "DataCopyBytesMedium", - runFunction: { copyBytes($0, data: medium) }, tags: d), + runFunction: { copyBytes($0*M, data: medium) }, tags: d), BenchmarkInfo(name: "DataAppendBytesSmall", - runFunction: { append($0, bytes: 3, to: small) }, tags: d), + runFunction: { append($0*M, bytes: 3, to: small) }, tags: d), BenchmarkInfo(name: "DataAppendBytesMedium", - runFunction: { append($0, bytes: 809, to: medium) }, tags: d), + runFunction: { append($0*M, bytes: 809, to: medium) }, tags: d), BenchmarkInfo(name: "DataAppendArray", - runFunction: { append($0, arraySize: 809, to: medium) }, tags: d), + runFunction: { append($0*M, arraySize: 809, to: medium) }, tags: d), BenchmarkInfo(name: "DataReset", - runFunction: { resetBytes($0, in: 431..<809, data: medium) }, tags: d), + runFunction: { resetBytes($0*M, in: 431..<809, data: medium) }, tags: d), BenchmarkInfo(name: "DataReplaceSmall", runFunction: { - replace($0, data: medium, subrange:431..<809, with: small) }, tags: d), + replace($0*M, data: medium, subrange:431..<809, with: small) }, tags: d), BenchmarkInfo(name: "DataReplaceMedium", runFunction: { - replace($0, data: medium, subrange:431..<809, with: medium) }, tags: d), + replace($0*M, data: medium, subrange:431..<809, with: medium) }, tags: d), BenchmarkInfo(name: "DataReplaceLarge", runFunction: { - replace($0, data: medium, subrange:431..<809, with: large) }, tags: d), + replace($0*M, data: medium, subrange:431..<809, with: large) }, tags: d), BenchmarkInfo(name: "DataReplaceSmallBuffer", runFunction: { - replaceBuffer($0, data: medium, subrange:431..<809, with: small) }, + replaceBuffer($0*M, data: medium, subrange:431..<809, with: small) }, tags: d), BenchmarkInfo(name: "DataReplaceMediumBuffer", runFunction: { - replaceBuffer($0, data: medium, subrange:431..<809, with: medium) }, + replaceBuffer($0*M, data: medium, subrange:431..<809, with: medium) }, tags: d), BenchmarkInfo(name: "DataReplaceLargeBuffer", runFunction: { - replaceBuffer($0, data: medium, subrange:431..<809, with: large) }, + replaceBuffer($0*M, data: medium, subrange:431..<809, with: large) }, tags: d), BenchmarkInfo(name: "DataAppendSequence", - runFunction: { append($0, sequenceLength: 809, to: medium) }, tags: d), + runFunction: { append($0*M, sequenceLength: 809, to: medium) }, tags: d), BenchmarkInfo(name: "DataAppendDataSmallToSmall", - runFunction: { append($0, data: small, to: small) }, tags: d), + runFunction: { append($0*M, data: small, to: small) }, tags: d), BenchmarkInfo(name: "DataAppendDataSmallToMedium", - runFunction: { append($0, data: small, to: medium) }, tags: d), + runFunction: { append($0*M, data: small, to: medium) }, tags: d), BenchmarkInfo(name: "DataAppendDataSmallToLarge", - runFunction: { append($0, data: small, to: large) }, tags: d), + runFunction: { append($0*M, data: small, to: large) }, tags: d), BenchmarkInfo(name: "DataAppendDataMediumToSmall", - runFunction: { append($0, data: medium, to: small) }, tags: d), + runFunction: { append($0*M, data: medium, to: small) }, tags: d), BenchmarkInfo(name: "DataAppendDataMediumToMedium", - runFunction: { append($0, data: medium, to: medium) }, tags: d), + runFunction: { append($0*M, data: medium, to: medium) }, tags: d), BenchmarkInfo(name: "DataAppendDataMediumToLarge", - runFunction: { append($0, data: medium, to: large) }, tags: d), + runFunction: { append($0*M, data: medium, to: large) }, tags: d), BenchmarkInfo(name: "DataAppendDataLargeToSmall", - runFunction: { append($0, data: large, to: small) }, tags: d), + runFunction: { append($0*M, data: large, to: small) }, tags: d), BenchmarkInfo(name: "DataAppendDataLargeToMedium", - runFunction: { append($0, data: large, to: medium) }, tags: d), + runFunction: { append($0*M, data: large, to: medium) }, tags: d), BenchmarkInfo(name: "DataAppendDataLargeToLarge", - runFunction: { append($0, data: large, to: large) }, tags: d), + runFunction: { append($0*M, data: large, to: large) }, tags: d), BenchmarkInfo(name: "DataToStringEmpty", - runFunction: { string($0, from: emptyData) }, tags: d, legacyFactor: 50), + runFunction: { string($0*S, from: emptyData) }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "DataToStringSmall", - runFunction: { string($0, from: smallData) }, tags: d, legacyFactor: 50), + runFunction: { string($0*S, from: smallData) }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "DataToStringMedium", - runFunction: { string($0, from: mediumData) }, tags: d, legacyFactor: 50), + runFunction: { string($0*S, from: mediumData) }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "StringToDataEmpty", - runFunction: { data($0, from: emptyString) }, tags: d, legacyFactor: 50), + runFunction: { data($0*S, from: emptyString) }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "StringToDataSmall", - runFunction: { data($0, from: smallString) }, tags: d, legacyFactor: 50), + runFunction: { data($0*S, from: smallString) }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "StringToDataMedium", - runFunction: { data($0, from: mediumString) }, tags: d, legacyFactor: 50), + runFunction: { data($0*S, from: mediumString) }, tags: d, legacyFactor: 50), ] let emptyString = "" @@ -191,7 +196,7 @@ func sampleData(_ type: SampleKind) -> Data { @inline(never) func withUnsafeBytes(_ N: Int, data: Data) { - for _ in 0..<10000*N { + for _ in 1...N { data.withUnsafeBytes { (ptr: UnsafePointer) in blackHole(ptr.pointee) } @@ -200,7 +205,7 @@ func withUnsafeBytes(_ N: Int, data: Data) { @inline(never) func withUnsafeMutableBytes(_ N: Int, data: Data) { - for _ in 0..<10000*N { + for _ in 1...N { var copy = data copy.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer) in // Mutate a byte @@ -214,7 +219,7 @@ func copyBytes(_ N: Int, data: Data) { let amount = data.count var buffer = UnsafeMutablePointer.allocate(capacity: amount) defer { buffer.deallocate() } - for _ in 0..<10000*N { + for _ in 1...N { data.copyBytes(to: buffer, from: 0.., data: Data) { - for _ in 0..<10000*N { + for _ in 1...N { var copy = data copy.resetBytes(in: range) } @@ -265,7 +270,7 @@ func replace( subrange range: Range, with replacement: Data ) { - for _ in 0..<10000*N { + for _ in 1...N { var copy = data copy.replaceSubrange(range, with: replacement) } @@ -281,7 +286,7 @@ func replaceBuffer( replacement.withUnsafeBytes { (bytes: UnsafePointer) in let buffer = UnsafeBufferPointer(start: bytes, count: replacement.count) - for _ in 0..<10000*N { + for _ in 1...N { var copy = data copy.replaceSubrange(range, with: buffer) } @@ -291,7 +296,7 @@ func replaceBuffer( @inline(never) func append(_ N: Int, data: Data, to target: Data) { var copy: Data - for _ in 0..<10000*N { + for _ in 1...N { copy = target copy.append(data) } @@ -299,7 +304,7 @@ func append(_ N: Int, data: Data, to target: Data) { @inline(never) public func count(_ N: Int, data: Data) { - for _ in 0..<10000*N { + for _ in 1...N { blackHole(data.count) } } @@ -309,7 +314,7 @@ public func setCount(_ N: Int, data: Data, extra: Int) { var copy = data let count = data.count + extra let orig = data.count - for _ in 0..<10000*N { + for _ in 1...N { copy.count = count copy.count = orig } @@ -317,14 +322,14 @@ public func setCount(_ N: Int, data: Data, extra: Int) { @inline(never) public func string(_ N: Int, from data: Data) { - for _ in 0..<200 * N { + for _ in 1...N { blackHole(String(decoding: data, as: UTF8.self)) } } @inline(never) public func data(_ N: Int, from string: String) { - for _ in 0..<200 * N { + for _ in 1...N { blackHole(Data(string.utf8)) } } From 928d01503788977c4802bd850e362633ecc9bbe9 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 22:31:30 +0100 Subject: [PATCH 24/26] [benchmark] DataBenchmarks Legacy Factor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adjusted the multipliers to run in under 1000 μs. The inner loop multipliers are divided by the `legacyFactor` to achieve the same reported runtime, but in a shorter time and with better precision (less accumulated error). --- benchmark/single-source/DataBenchmarks.swift | 90 ++++++++++++-------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 41ce320d2f0f4..d3fcd5ecc7183 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -22,26 +22,28 @@ let S = 200 /// String conversions public let DataBenchmarks = [ BenchmarkInfo(name: "DataCreateEmpty", - runFunction: { for _ in 0..<$0*I { blackHole(Data()) } }, tags: d), + runFunction: { for _ in 0..<$0*I/10 { blackHole(Data()) } }, + tags: d, legacyFactor: 10), BenchmarkInfo(name: "DataCreateSmall", - runFunction: { for _ in 0..<$0*I { blackHole(sampleData(.small)) } }, - tags: d), + runFunction: { for _ in 0..<$0*I/1000 { blackHole(sampleData(.small)) } }, + tags: d, legacyFactor: 1000), BenchmarkInfo(name: "DataCreateMedium", - runFunction: { for _ in 0..<$0*M { blackHole(sampleData(.medium)) } }, - tags: d), + runFunction: { for _ in 0..<$0*M/100 { blackHole(sampleData(.medium)) } }, + tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataCreateEmptyArray", - runFunction: { for _ in 0..<$0*I { blackHole(Data([])) } }, tags: d), + runFunction: { for _ in 0..<$0*I/50 { blackHole(Data([])) } }, tags: d, + legacyFactor: 50), BenchmarkInfo(name: "DataCreateSmallArray", - runFunction: { for _ in 0..<$0*I { blackHole(Data( - [0, 1, 2, 3, 4, 5, 6])) } }, tags: d), + runFunction: { for _ in 0..<$0*I/50 { blackHole(Data( + [0, 1, 2, 3, 4, 5, 6])) } }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "DataCreateMediumArray", - runFunction: { for _ in 0..<$0*M { blackHole(Data([ + runFunction: { for _ in 0..<$0*M/20 { blackHole(Data([ 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, - ])) } }, tags: d), + ])) } }, tags: d, legacyFactor: 20), BenchmarkInfo(name: "DataSubscriptSmall", runFunction: { for _ in 0..<$0*M { blackHole(small[1]) } }, tags: d), @@ -56,7 +58,8 @@ public let DataBenchmarks = [ BenchmarkInfo(name: "DataSetCountSmall", runFunction: { setCount($0*M, data: small, extra: 3) }, tags: d), BenchmarkInfo(name: "DataSetCountMedium", - runFunction: { setCount($0*M, data: medium, extra: 100) }, tags: d), + runFunction: { setCount($0*M/10, data: medium, extra: 100) }, tags: d, + legacyFactor: 10), BenchmarkInfo(name: "DataAccessBytesSmall", runFunction: { withUnsafeBytes($0*M, data: small) }, tags: d), @@ -64,64 +67,81 @@ public let DataBenchmarks = [ runFunction: { withUnsafeBytes($0*M, data: medium) }, tags: d), BenchmarkInfo(name: "DataMutateBytesSmall", - runFunction: { withUnsafeMutableBytes($0*M, data: small) }, tags: d), + runFunction: { withUnsafeMutableBytes($0*M/20, data: small) }, tags: d, + legacyFactor: 20), BenchmarkInfo(name: "DataMutateBytesMedium", - runFunction: { withUnsafeMutableBytes($0*M, data: medium) }, tags: d), + runFunction: { withUnsafeMutableBytes($0*M/20, data: medium) }, tags: d, + legacyFactor: 20), BenchmarkInfo(name: "DataCopyBytesSmall", runFunction: { copyBytes($0*M, data: small) }, tags: d), BenchmarkInfo(name: "DataCopyBytesMedium", - runFunction: { copyBytes($0*M, data: medium) }, tags: d), + runFunction: { copyBytes($0*M/2, data: medium) }, tags: d, + legacyFactor: 2), BenchmarkInfo(name: "DataAppendBytesSmall", runFunction: { append($0*M, bytes: 3, to: small) }, tags: d), BenchmarkInfo(name: "DataAppendBytesMedium", - runFunction: { append($0*M, bytes: 809, to: medium) }, tags: d), + runFunction: { append($0*M/20, bytes: 809, to: medium) }, tags: d, + legacyFactor: 20), BenchmarkInfo(name: "DataAppendArray", - runFunction: { append($0*M, arraySize: 809, to: medium) }, tags: d), + runFunction: { append($0*M/100, arraySize: 809, to: medium) }, tags: d, + legacyFactor: 100), BenchmarkInfo(name: "DataReset", - runFunction: { resetBytes($0*M, in: 431..<809, data: medium) }, tags: d), + runFunction: { resetBytes($0*M/100, in: 431..<809, data: medium) }, + tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceSmall", runFunction: { - replace($0*M, data: medium, subrange:431..<809, with: small) }, tags: d), + replace($0*M/100, data: medium, subrange:431..<809, with: small) }, + tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceMedium", runFunction: { - replace($0*M, data: medium, subrange:431..<809, with: medium) }, tags: d), + replace($0*M/100, data: medium, subrange:431..<809, with: medium) }, + tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceLarge", runFunction: { - replace($0*M, data: medium, subrange:431..<809, with: large) }, tags: d), + replace($0*M/100, data: medium, subrange:431..<809, with: large) }, + tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceSmallBuffer", runFunction: { - replaceBuffer($0*M, data: medium, subrange:431..<809, with: small) }, - tags: d), + replaceBuffer($0*M/100, data: medium, subrange:431..<809, with: small) }, + tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceMediumBuffer", runFunction: { - replaceBuffer($0*M, data: medium, subrange:431..<809, with: medium) }, - tags: d), + replaceBuffer($0*M/100, data: medium, subrange:431..<809, with: medium) }, + tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceLargeBuffer", runFunction: { - replaceBuffer($0*M, data: medium, subrange:431..<809, with: large) }, + replaceBuffer($0*10, data: medium, subrange:431..<809, with: large) }, tags: d), BenchmarkInfo(name: "DataAppendSequence", - runFunction: { append($0*M, sequenceLength: 809, to: medium) }, tags: d), + runFunction: { append($0*M/100, sequenceLength: 809, to: medium) }, + tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataAppendDataSmallToSmall", - runFunction: { append($0*M, data: small, to: small) }, tags: d), + runFunction: { append($0*M/20, data: small, to: small) }, tags: d, + legacyFactor: 20), BenchmarkInfo(name: "DataAppendDataSmallToMedium", - runFunction: { append($0*M, data: small, to: medium) }, tags: d), + runFunction: { append($0*M/20, data: small, to: medium) }, tags: d, + legacyFactor: 20), BenchmarkInfo(name: "DataAppendDataSmallToLarge", - runFunction: { append($0*M, data: small, to: large) }, tags: d), + runFunction: { append($0*M/200, data: small, to: large) }, tags: d, + legacyFactor: 200), BenchmarkInfo(name: "DataAppendDataMediumToSmall", - runFunction: { append($0*M, data: medium, to: small) }, tags: d), + runFunction: { append($0*M/20, data: medium, to: small) }, tags: d, + legacyFactor: 20), BenchmarkInfo(name: "DataAppendDataMediumToMedium", - runFunction: { append($0*M, data: medium, to: medium) }, tags: d), + runFunction: { append($0*M/20, data: medium, to: medium) }, tags: d, + legacyFactor: 20), BenchmarkInfo(name: "DataAppendDataMediumToLarge", - runFunction: { append($0*M, data: medium, to: large) }, tags: d), + runFunction: { append($0*50, data: medium, to: large) }, tags: d), BenchmarkInfo(name: "DataAppendDataLargeToSmall", - runFunction: { append($0*M, data: large, to: small) }, tags: d), + runFunction: { append($0*M/200, data: large, to: small) }, tags: d, + legacyFactor: 200), BenchmarkInfo(name: "DataAppendDataLargeToMedium", - runFunction: { append($0*M, data: large, to: medium) }, tags: d), + runFunction: { append($0*M/200, data: large, to: medium) }, tags: d, + legacyFactor: 200), BenchmarkInfo(name: "DataAppendDataLargeToLarge", - runFunction: { append($0*M, data: large, to: large) }, tags: d), + runFunction: { append($0*50, data: large, to: large) }, tags: d), BenchmarkInfo(name: "DataToStringEmpty", runFunction: { string($0*S, from: emptyData) }, tags: d, legacyFactor: 50), From 1df944c3002a6f6f1caedd43edbf612b0a581390 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 4 Jan 2019 23:50:18 +0100 Subject: [PATCH 25/26] [benchmark] Fix DataSubscript fragile inlining? --- benchmark/single-source/DataBenchmarks.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index d3fcd5ecc7183..77e700a2d60ab 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -46,9 +46,11 @@ public let DataBenchmarks = [ ])) } }, tags: d, legacyFactor: 20), BenchmarkInfo(name: "DataSubscriptSmall", - runFunction: { for _ in 0..<$0*M { blackHole(small[1]) } }, tags: d), + runFunction: { let data = small + for _ in 0..<$0*M { blackHole(data[1]) } }, tags: d), BenchmarkInfo(name: "DataSubscriptMedium", - runFunction: { for _ in 0..<$0*M { blackHole(medium[521]) } }, tags: d), + runFunction: { let data = medium + for _ in 0..<$0*M { blackHole(data[521]) } }, tags: d), BenchmarkInfo(name: "DataCountSmall", runFunction: { count($0*M, data: small) }, tags: d), From 7db46b3b1402fd7a9fd14899a9d597df1a5522b5 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Tue, 8 Jan 2019 01:22:22 +0100 Subject: [PATCH 26/26] [benchmark] Inlined loop miltipliers Also added 2 forgotten legacy factors. --- benchmark/single-source/DataBenchmarks.swift | 99 ++++++++++---------- 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/benchmark/single-source/DataBenchmarks.swift b/benchmark/single-source/DataBenchmarks.swift index 77e700a2d60ab..b9a35f2f1dd5c 100644 --- a/benchmark/single-source/DataBenchmarks.swift +++ b/benchmark/single-source/DataBenchmarks.swift @@ -15,30 +15,25 @@ import Foundation let d: [BenchmarkCategory] = [.validation, .api, .Data] -/// Workload scaling: Inner loop multipliers -let M = 10_000 /// default -let I = 100_000 /// Data initialization -let S = 200 /// String conversions - public let DataBenchmarks = [ BenchmarkInfo(name: "DataCreateEmpty", - runFunction: { for _ in 0..<$0*I/10 { blackHole(Data()) } }, + runFunction: { for _ in 0..<$0*10_000 { blackHole(Data()) } }, tags: d, legacyFactor: 10), BenchmarkInfo(name: "DataCreateSmall", - runFunction: { for _ in 0..<$0*I/1000 { blackHole(sampleData(.small)) } }, + runFunction: { for _ in 0..<$0*100 { blackHole(sampleData(.small)) } }, tags: d, legacyFactor: 1000), BenchmarkInfo(name: "DataCreateMedium", - runFunction: { for _ in 0..<$0*M/100 { blackHole(sampleData(.medium)) } }, + runFunction: { for _ in 0..<$0*100 { blackHole(sampleData(.medium)) } }, tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataCreateEmptyArray", - runFunction: { for _ in 0..<$0*I/50 { blackHole(Data([])) } }, tags: d, + runFunction: { for _ in 0..<$0*2_000 { blackHole(Data([])) } }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "DataCreateSmallArray", - runFunction: { for _ in 0..<$0*I/50 { blackHole(Data( + runFunction: { for _ in 0..<$0*2_000 { blackHole(Data( [0, 1, 2, 3, 4, 5, 6])) } }, tags: d, legacyFactor: 50), BenchmarkInfo(name: "DataCreateMediumArray", - runFunction: { for _ in 0..<$0*M/20 { blackHole(Data([ + runFunction: { for _ in 0..<$0*500 { blackHole(Data([ 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, @@ -47,117 +42,125 @@ public let DataBenchmarks = [ BenchmarkInfo(name: "DataSubscriptSmall", runFunction: { let data = small - for _ in 0..<$0*M { blackHole(data[1]) } }, tags: d), + for _ in 0..<$0*10_000 { blackHole(data[1]) } }, tags: d), BenchmarkInfo(name: "DataSubscriptMedium", runFunction: { let data = medium - for _ in 0..<$0*M { blackHole(data[521]) } }, tags: d), + for _ in 0..<$0*10_000 { blackHole(data[521]) } }, tags: d), BenchmarkInfo(name: "DataCountSmall", - runFunction: { count($0*M, data: small) }, tags: d), + runFunction: { count($0*10_000, data: small) }, tags: d), BenchmarkInfo(name: "DataCountMedium", - runFunction: { count($0*M, data: medium) }, tags: d), + runFunction: { count($0*10_000, data: medium) }, tags: d), BenchmarkInfo(name: "DataSetCountSmall", - runFunction: { setCount($0*M, data: small, extra: 3) }, tags: d), + runFunction: { setCount($0*10_000, data: small, extra: 3) }, tags: d), BenchmarkInfo(name: "DataSetCountMedium", - runFunction: { setCount($0*M/10, data: medium, extra: 100) }, tags: d, + runFunction: { setCount($0*1_000, data: medium, extra: 100) }, tags: d, legacyFactor: 10), BenchmarkInfo(name: "DataAccessBytesSmall", - runFunction: { withUnsafeBytes($0*M, data: small) }, tags: d), + runFunction: { withUnsafeBytes($0*10_000, data: small) }, tags: d), BenchmarkInfo(name: "DataAccessBytesMedium", - runFunction: { withUnsafeBytes($0*M, data: medium) }, tags: d), + runFunction: { withUnsafeBytes($0*10_000, data: medium) }, tags: d), BenchmarkInfo(name: "DataMutateBytesSmall", - runFunction: { withUnsafeMutableBytes($0*M/20, data: small) }, tags: d, + runFunction: { withUnsafeMutableBytes($0*500, data: small) }, tags: d, legacyFactor: 20), BenchmarkInfo(name: "DataMutateBytesMedium", - runFunction: { withUnsafeMutableBytes($0*M/20, data: medium) }, tags: d, + runFunction: { withUnsafeMutableBytes($0*500, data: medium) }, tags: d, legacyFactor: 20), BenchmarkInfo(name: "DataCopyBytesSmall", - runFunction: { copyBytes($0*M, data: small) }, tags: d), + runFunction: { copyBytes($0*10_000, data: small) }, tags: d), BenchmarkInfo(name: "DataCopyBytesMedium", - runFunction: { copyBytes($0*M/2, data: medium) }, tags: d, + runFunction: { copyBytes($0*5_000, data: medium) }, tags: d, legacyFactor: 2), BenchmarkInfo(name: "DataAppendBytesSmall", - runFunction: { append($0*M, bytes: 3, to: small) }, tags: d), + runFunction: { append($0*10_000, bytes: 3, to: small) }, tags: d), BenchmarkInfo(name: "DataAppendBytesMedium", - runFunction: { append($0*M/20, bytes: 809, to: medium) }, tags: d, + runFunction: { append($0*500, bytes: 809, to: medium) }, tags: d, legacyFactor: 20), BenchmarkInfo(name: "DataAppendArray", - runFunction: { append($0*M/100, arraySize: 809, to: medium) }, tags: d, + runFunction: { append($0*100, arraySize: 809, to: medium) }, tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReset", - runFunction: { resetBytes($0*M/100, in: 431..<809, data: medium) }, + runFunction: { resetBytes($0*100, in: 431..<809, data: medium) }, tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceSmall", runFunction: { - replace($0*M/100, data: medium, subrange:431..<809, with: small) }, + replace($0*100, data: medium, subrange:431..<809, with: small) }, tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceMedium", runFunction: { - replace($0*M/100, data: medium, subrange:431..<809, with: medium) }, + replace($0*100, data: medium, subrange:431..<809, with: medium) }, tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceLarge", runFunction: { - replace($0*M/100, data: medium, subrange:431..<809, with: large) }, + replace($0*100, data: medium, subrange:431..<809, with: large) }, tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceSmallBuffer", runFunction: { - replaceBuffer($0*M/100, data: medium, subrange:431..<809, with: small) }, + replaceBuffer($0*100, data: medium, subrange:431..<809, with: small) }, tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceMediumBuffer", runFunction: { - replaceBuffer($0*M/100, data: medium, subrange:431..<809, with: medium) }, + replaceBuffer($0*100, data: medium, subrange:431..<809, with: medium) }, tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataReplaceLargeBuffer", runFunction: { replaceBuffer($0*10, data: medium, subrange:431..<809, with: large) }, tags: d), BenchmarkInfo(name: "DataAppendSequence", - runFunction: { append($0*M/100, sequenceLength: 809, to: medium) }, + runFunction: { append($0*100, sequenceLength: 809, to: medium) }, tags: d, legacyFactor: 100), BenchmarkInfo(name: "DataAppendDataSmallToSmall", - runFunction: { append($0*M/20, data: small, to: small) }, tags: d, + runFunction: { append($0*500, data: small, to: small) }, tags: d, legacyFactor: 20), BenchmarkInfo(name: "DataAppendDataSmallToMedium", - runFunction: { append($0*M/20, data: small, to: medium) }, tags: d, + runFunction: { append($0*500, data: small, to: medium) }, tags: d, legacyFactor: 20), BenchmarkInfo(name: "DataAppendDataSmallToLarge", - runFunction: { append($0*M/200, data: small, to: large) }, tags: d, + runFunction: { append($0*50, data: small, to: large) }, tags: d, legacyFactor: 200), BenchmarkInfo(name: "DataAppendDataMediumToSmall", - runFunction: { append($0*M/20, data: medium, to: small) }, tags: d, + runFunction: { append($0*500, data: medium, to: small) }, tags: d, legacyFactor: 20), BenchmarkInfo(name: "DataAppendDataMediumToMedium", - runFunction: { append($0*M/20, data: medium, to: medium) }, tags: d, + runFunction: { append($0*500, data: medium, to: medium) }, tags: d, legacyFactor: 20), BenchmarkInfo(name: "DataAppendDataMediumToLarge", - runFunction: { append($0*50, data: medium, to: large) }, tags: d), + runFunction: { append($0*50, data: medium, to: large) }, tags: d, + legacyFactor: 200), BenchmarkInfo(name: "DataAppendDataLargeToSmall", - runFunction: { append($0*M/200, data: large, to: small) }, tags: d, + runFunction: { append($0*50, data: large, to: small) }, tags: d, legacyFactor: 200), BenchmarkInfo(name: "DataAppendDataLargeToMedium", - runFunction: { append($0*M/200, data: large, to: medium) }, tags: d, + runFunction: { append($0*50, data: large, to: medium) }, tags: d, legacyFactor: 200), BenchmarkInfo(name: "DataAppendDataLargeToLarge", - runFunction: { append($0*50, data: large, to: large) }, tags: d), + runFunction: { append($0*50, data: large, to: large) }, tags: d, + legacyFactor: 200), BenchmarkInfo(name: "DataToStringEmpty", - runFunction: { string($0*S, from: emptyData) }, tags: d, legacyFactor: 50), + runFunction: { string($0*200, from: emptyData) }, tags: d, + legacyFactor: 50), BenchmarkInfo(name: "DataToStringSmall", - runFunction: { string($0*S, from: smallData) }, tags: d, legacyFactor: 50), + runFunction: { string($0*200, from: smallData) }, tags: d, + legacyFactor: 50), BenchmarkInfo(name: "DataToStringMedium", - runFunction: { string($0*S, from: mediumData) }, tags: d, legacyFactor: 50), + runFunction: { string($0*200, from: mediumData) }, tags: d, + legacyFactor: 50), BenchmarkInfo(name: "StringToDataEmpty", - runFunction: { data($0*S, from: emptyString) }, tags: d, legacyFactor: 50), + runFunction: { data($0*200, from: emptyString) }, tags: d, + legacyFactor: 50), BenchmarkInfo(name: "StringToDataSmall", - runFunction: { data($0*S, from: smallString) }, tags: d, legacyFactor: 50), + runFunction: { data($0*200, from: smallString) }, tags: d, + legacyFactor: 50), BenchmarkInfo(name: "StringToDataMedium", - runFunction: { data($0*S, from: mediumString) }, tags: d, legacyFactor: 50), + runFunction: { data($0*200, from: mediumString) }, tags: d, + legacyFactor: 50), ] let emptyString = ""