blob: 1c65ca84fefc7d9ec340eb494f49f61bb2731e22 [file] [log] [blame]
//===--- CharacterProperties.swift ----------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
% # Ignore the following warning. This _is_ the correct file to edit.
////////////////////////////////////////////////////////////////////////////////
// WARNING: This file is manually generated from .gyb template and should not
// be directly modified. Instead, make changes to CharacterProperties.swift.gyb
// and run scripts/generate_harness/generate_harness.py to regenerate this file.
////////////////////////////////////////////////////////////////////////////////
import TestsUtils
import Foundation
public let CharacterPropertiesFetch = BenchmarkInfo(
name: "CharacterPropertiesFetch",
runFunction: run_CharacterPropertiesFetch,
tags: [.validation, .api, .String])
public let CharacterPropertiesStashed = BenchmarkInfo(
name: "CharacterPropertiesStashed",
runFunction: run_CharacterPropertiesStashed,
tags: [.validation, .api, .String],
setUpFunction: { run_CharacterPropertiesStashed(1) },
tearDownFunction: nil)
public let CharacterPropertiesStashedMemo = BenchmarkInfo(
name: "CharacterPropertiesStashedMemo",
runFunction: run_CharacterPropertiesStashedMemo,
tags: [.validation, .api, .String])
public let CharacterPropertiesPrecomputed = BenchmarkInfo(
name: "CharacterPropertiesPrecomputed",
runFunction: run_CharacterPropertiesPrecomputed,
tags: [.validation, .api, .String],
setUpFunction: { run_CharacterPropertiesPrecomputed(1) },
tearDownFunction: nil)
extension Character {
var firstScalar: UnicodeScalar { return unicodeScalars.first! }
}
% Properties = { "Alphanumeric": "alphanumerics", \
% "Capitalized": "capitalizedLetters", \
% "Control": "controlCharacters", \
% "Decimal": "decimalDigits", \
% "Letter": "letters", \
% "Lowercase": "lowercaseLetters", \
% "Uppercase": "uppercaseLetters", \
% "Newline": "newlines", \
% "Whitespace": "whitespaces", \
% "Punctuation": "punctuationCharacters" \
% }
// Fetch the CharacterSet for every call
% for Property, Set in Properties.items():
func is${Property}(_ c: Character) -> Bool {
return CharacterSet.${Set}.contains(c.firstScalar)
}
% end
// Stash the set
% for Property, Set in Properties.items():
let ${Set} = CharacterSet.${Set}
func is${Property}Stashed(_ c: Character) -> Bool {
return ${Set}.contains(c.firstScalar)
}
% end
// Memoize the stashed set
% for Property, Set in Properties.items():
var ${Set}Memo = Set<UInt32>()
func is${Property}StashedMemo(_ c: Character) -> Bool {
let scalar = c.firstScalar
if ${Set}Memo.contains(scalar.value) { return true }
if ${Set}.contains(scalar) {
${Set}Memo.insert(scalar.value)
return true
}
return false
}
% end
// Precompute whole scalar set
% for Property, Set in Properties.items():
var ${Set}Precomputed: Set<UInt32> = {
var result = Set<UInt32>()
for i in 0...0x0010_FFFF {
guard let scalar = UnicodeScalar(i) else { continue }
if ${Set}.contains(scalar) {
result.insert(scalar.value)
}
}
return result
}()
func is${Property}Precomputed(_ c: Character) -> Bool {
return ${Set}Precomputed.contains(c.firstScalar.value)
}
% end
// Compute on the fly
//
// TODO: If UnicodeScalars ever exposes category, etc., implement the others!
func isNewlineComputed(_ c: Character) -> Bool {
switch c.firstScalar.value {
case 0x000A...0x000D: return true
case 0x0085: return true
case 0x2028...0x2029: return true
default: return false
}
}
let workload = """
the quick brown 🦊 jumped over the lazy 🐢.
Π² Ρ‡Π°Ρ‰Π°Ρ… юга ΠΆΠΈΠ»-Π±Ρ‹Π» цитрус? Π΄Π°, Π½ΠΎ Ρ„Π°Π»ΡŒΡˆΠΈΠ²Ρ‹ΠΉ экзСмпляр
π“€€π“€€π““π“²π“ƒ”π“ƒ—π“ƒ€π“ƒπ“ƒ‚π“ƒƒπ“†Œπ“†π“†Žπ“†π“†π“†‘π“†’π“†²π“Ώ
πŸκƒ•θΊβ€ΎβˆΎπŸ“¦βΊ¨
πŸ‘πŸ‘©β€πŸ‘©β€πŸ‘§β€πŸ‘§πŸ‘¨β€πŸ‘¨β€πŸ‘¦β€πŸ‘¦πŸ‡ΊπŸ‡ΈπŸ‡¨πŸ‡¦πŸ‡²πŸ‡½πŸ‘πŸ»πŸ‘πŸΌπŸ‘πŸ½πŸ‘πŸΎπŸ‘πŸΏ
Lorem ipsum something something something...
"""
@inline(never)
public func run_CharacterPropertiesFetch(_ N: Int) {
for _ in 1...N*10 {
for c in workload {
% for Property, Set in Properties.items():
blackHole(is${Property}(c))
% end
}
}
}
@inline(never)
public func run_CharacterPropertiesStashed(_ N: Int) {
for _ in 1...N*10 {
for c in workload {
% for Property, Set in Properties.items():
blackHole(is${Property}Stashed(c))
% end
}
}
}
@inline(never)
public func run_CharacterPropertiesStashedMemo(_ N: Int) {
for _ in 1...N*10 {
for c in workload {
% for Property, Set in Properties.items():
blackHole(is${Property}StashedMemo(c))
% end
}
}
}
@inline(never)
public func run_CharacterPropertiesPrecomputed(_ N: Int) {
for _ in 1...N*10 {
for c in workload {
% for Property, Set in Properties.items():
blackHole(is${Property}Precomputed(c))
% end
}
}
}
// TODO: run_CharacterPropertiesComputed