Swift: add, adds, append, appends 속도 비교
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]을 배열에 더하는 연산을 다중 add, adds, 다중 append, appends로 각각 수행할 때의 속도 비교다중 add를 제외하면 평이하며, 다중 add의 경우 n이 100000000 일 때, 다른 API에 비해 3배의 속도 차이가 발생 import SwiftUIfunc measure(label: String, repeatCount: Int, function: () -> ()) { let time = ContinuousClock().measure { for _ in 1...repeatCount { function() } } print(label, ":", time)}struct ContentView: View { @State ..
2025. 3. 30.
Swift: async let 수행 순서
async let의 수행 순서는 await 순서에 따름func function(_ name: String, _ i: Int) async -> Int { print("sleep: ", name, i) sleep(UInt32(i)) print("wake up: ", name, i) return i}async let a = function("a", 10)async let b = function("b", 3)async let c = function("c", 2)async let d = function("d", 5)async let e = function("e", 3)async let f = function("f", 5)async let g = function("g", 3)async let ..
2025. 3. 30.
Swift 알고리즘 관련 문법
조건 splitlet str = "abd124kbksbjb62".split { !$0.isNumber }print(str) // ["124", "62"] dict 필터let s = [1, 2, 2, 3, 3, 3, 4, 4, 4]let dict = Dictionary(grouping: Array(s).map(String.init), by: { $0 }).filter { $0.value.count > 1 }print(dict) // ["3": ["3", "3", "3"], "2": ["2", "2"], "4": ["4", "4", "4"]] 여러 조건 splitlet str = "nabcvcvacbacac".split { $0 == "a" || $0 == "b" || $0 == "c" }.map { Str..
2025. 3. 30.