Skip to content

Instantly share code, notes, and snippets.

@iosdevzone
Created October 2, 2014 00:18
Show Gist options
  • Save iosdevzone/18a5bc1ab30de20a5810 to your computer and use it in GitHub Desktop.
Save iosdevzone/18a5bc1ab30de20a5810 to your computer and use it in GitHub Desktop.
File to demonstrate very slow compilation times on swift when string concatenation operator used rather than string interpolation.
class Foo
{
let a = "a"
let b = "b"
let c = "c"
let values = [ "A", "B", "C", "D", "E" ]
var rawValues: String
{
let a = self.a
let b = self.b
let c = self.c
var s : String = "static let \(a) = [ "
#if false
/*
real 0m35.143s
user 0m29.888s
sys 0m0.984s
*/
let d : [String] = values.map { $0 + ": " + b + "(" + c + $0 + ")" }
#else
/*
real 0m0.226s
user 0m0.136s
sys 0m0.059s
*/
let d : [String] = values.map { "\($0): \(b)(\(c)\($0))" }
#endif
var j = join(", \n", d)
s += j
s += " ]\n"
return s
}
}
var f = Foo()
println(f.rawValues)
/*
Model Name: MacBook Air
Model Identifier: MacBookAir3,1
Processor Name: Intel Core 2 Duo
Processor Speed: 1.4 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache: 3 MB
Memory: 2 GB
Bus Speed: 800 MHz
System Version: OS X 10.9.4 (13E28)
Kernel Version: Darwin 13.3.0
Boot Volume: New Macintosh HD
Boot Mode: Normal
Computer Name: inu
User Name: idz (idz)
Secure Virtual Memory: Enabled
Time since boot: 6:21
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment