|
| 1 | +//===--- StringRepeating.swift --------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +import TestsUtils |
| 14 | + |
| 15 | +public let benchmarks = [ |
| 16 | + BenchmarkInfo(name: "String.initRepeating.1AsciiChar.Count100", |
| 17 | + runFunction: run_singleAsciiCharacterCount100, |
| 18 | + tags: [.validation, .api, .String]), |
| 19 | + BenchmarkInfo(name: "String.initRepeating.26AsciiChar.Count2", |
| 20 | + runFunction: run_26AsciiCharactersCount2, |
| 21 | + tags: [.validation, .api, .String]), |
| 22 | + BenchmarkInfo(name: "String.initRepeating.33CyrillicChar.Count2", |
| 23 | + runFunction: run_33CyrillicCharactersCount2, |
| 24 | + tags: [.validation, .api, .String]), |
| 25 | + BenchmarkInfo(name: "String.initRepeating.longMixStr.Count100", |
| 26 | + runFunction: run_longMixedStringCount100, |
| 27 | + tags: [.validation, .api, .String]) |
| 28 | +] |
| 29 | + |
| 30 | +@inline(never) |
| 31 | +public func run_singleAsciiCharacterCount100(N: Int) { |
| 32 | + let string = "x" |
| 33 | + for _ in 1...200*N { |
| 34 | + blackHole(String(repeating: getString(string), count: 100)) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +@inline(never) |
| 39 | +public func run_26AsciiCharactersCount2(N: Int) { |
| 40 | + let string = "abcdefghijklmnopqrstuvwxyz" |
| 41 | + for _ in 1...200*N { |
| 42 | + blackHole(String(repeating: getString(string), count: 2)) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +@inline(never) |
| 47 | +public func run_33CyrillicCharactersCount2(N: Int) { |
| 48 | + let string = "абвгґдеєжзиіїйклмнопрстуфхцчшщьюя" |
| 49 | + for _ in 1...200*N { |
| 50 | + blackHole(String(repeating: getString(string), count: 2)) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +@inline(never) |
| 55 | +public func run_longMixedStringCount100(N: Int) { |
| 56 | + let string = """ |
| 57 | + Swift is a multi-paradigm, compiled programming language created for |
| 58 | + iOS, OS X, watchOS, tvOS and Linux development by Apple Inc. Swift is |
| 59 | + designed to work with Apple's Cocoa and Cocoa Touch frameworks and the |
| 60 | + large body of existing Objective-C code written for Apple products. Swift |
| 61 | + is intended to be more resilient to erroneous code (\"safer\") than |
| 62 | + Objective-C and also more concise. It is built with the LLVM compiler |
| 63 | + framework included in Xcode 6 and later and uses the Objective-C runtime, |
| 64 | + which allows C, Objective-C, C++ and Swift code to run within a single |
| 65 | + program. |
| 66 | + Існує багато варіацій уривків з Lorem Ipsum, але більшість з них зазнала |
| 67 | + певних змін на кшталт жартівливих вставок або змішування слів, які навіть |
| 68 | + не виглядають правдоподібно. |
| 69 | + 日本語の場合はランダムに生成された文章以外に、 |
| 70 | + 著作権が切れた小説などが利用されることもある。 |
| 71 | + 🦩 |
| 72 | + """ |
| 73 | + for _ in 1...200*N { |
| 74 | + blackHole(String(repeating: getString(string), count: 100)) |
| 75 | + } |
| 76 | +} |
0 commit comments