From 65574bcab2a38d55a18fe2c63e947073c2588f5a Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Thu, 3 Dec 2020 12:27:24 -0500 Subject: [PATCH] Include everything --- .../Contents.swift | 19 +++++++++++++++ .../Benchmark-Copying.swift | 24 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/0127-parsing-performance-pt1/parser-performance.playground/Contents.swift b/0127-parsing-performance-pt1/parser-performance.playground/Contents.swift index 2ae52de8..09a865be 100644 --- a/0127-parsing-performance-pt1/parser-performance.playground/Contents.swift +++ b/0127-parsing-performance-pt1/parser-performance.playground/Contents.swift @@ -33,3 +33,22 @@ acuteE1.unicodeScalars.elementsEqual(acuteE2.unicodeScalars) "πŸ‡Έ" "πŸ‡Ί" + "πŸ‡Έ" "\u{1F1FA}\u{1F1F8}" + + + +"πŸ‡ΊπŸ‡Έ".dropFirst() + +String("πŸ‡ΊπŸ‡Έ".unicodeScalars.dropFirst()) + +Array(acuteE1.utf8) +Array(acuteE2.utf8) + +Array("πŸ‡ΊπŸ‡Έ".unicodeScalars) +Array("πŸ‡ΊπŸ‡Έ".utf8) +Array("πŸ‘¨β€πŸ‘¨β€πŸ‘§β€πŸ‘§".unicodeScalars) +Array("πŸ‘¨β€πŸ‘¨β€πŸ‘§β€πŸ‘§".utf8) +"πŸ‘¨β€πŸ‘¨β€πŸ‘§β€πŸ‘§".utf8.count + +"πŸ‡ΊπŸ‡Έ".unicodeScalars.first == ("πŸ‡Ί" as Unicode.Scalar) + +"πŸ‡ΊπŸ‡Έ".utf8.starts(with: [240, 159, 135, 186]) diff --git a/0127-parsing-performance-pt1/string-performance/Sources/string-performance/Benchmark-Copying.swift b/0127-parsing-performance-pt1/string-performance/Sources/string-performance/Benchmark-Copying.swift index e3558b0f..c0b41cf1 100644 --- a/0127-parsing-performance-pt1/string-performance/Sources/string-performance/Benchmark-Copying.swift +++ b/0127-parsing-performance-pt1/string-performance/Sources/string-performance/Benchmark-Copying.swift @@ -1,7 +1,7 @@ import Benchmark let copyingSuite = BenchmarkSuite(name: "Copying") { suite in - let string = String.init(repeating: "A", count: 1_000_000) + let string = String.init(repeating: "πŸ‘¨β€πŸ‘¨β€πŸ‘§β€πŸ‘§", count: 1_000_000) suite.benchmark("String") { var copy = string @@ -24,5 +24,27 @@ let copyingSuite = BenchmarkSuite(name: "Copying") { suite in var copy3 = copy2 copy3.removeFirst() } + + suite.benchmark("UnicodeScalars") { + var copy = string[...].unicodeScalars + copy.removeFirst() + var copy1 = copy + copy1.removeFirst() + var copy2 = copy1 + copy2.removeFirst() + var copy3 = copy2 + copy3.removeFirst() + } + + suite.benchmark("UTF8") { + var copy = string[...].utf8 + copy.removeFirst() + var copy1 = copy + copy1.removeFirst() + var copy2 = copy1 + copy2.removeFirst() + var copy3 = copy2 + copy3.removeFirst() + } }