The original text was published in the Web of stepping
Swift includes a lot of modern language features, especially from some scripting languages like Javascript/ruby.
In addition Apple announced Swift , use some of the specially selected examples to declare the Swift performance significantly increasedfor ojbective C (40~50%), such as complex object ordering,
Apple does not claim that the Swift app is superior to the objective-c app , through a carefully selected case (perhaps using a known Objective-c language defects),
But cleverly left the overall performance to improve the impression. But the fact that the developers actually tested it was the opposite.
The developer Keith first gave his own test results, and the actual data showed. Swift has a much better performance than Objective C in simple loops, increments, assignments, array expansions, and string concatenation .
One possible explanation is that Swift uses class classes, always running ARC(Auto referrence Count ), while Objective C has many other data types that use C-style.
Detailed test methods, code, and data references such as the following:
loop (loop A Million times)
Swift: 0.0036s
Objective-c: .0021s (1.7x faster)
The loop has no action whatsoever. Actually, Swift is doing well here. Because Objective-c is like a simple C-language test under this test example. Note that the loop here is x=x+1
Auto-increment (Increment)
Swift: 0.024s
Objective-c: 0.0023s (10.4x Faster)
It is strange that Swift + + operations have serious performance problems that are 6 times times slower than x=x+1.
Assignment (Assign)
Swift: 0.024s
Objective-c: 0.0022s (10.9x faster)
This is just a simple statement x = y.
Presumably Swift uses arc, which retains and frees 1 million of times and apparently brings performance damage.
Add a string to an array (Append native string to native array)
Swift: 6.49s
Objective-c: 0.046s (141.1x faster)
Swift code uses a string array (array of string). objective-c is to add a nsstring to a nsmutablearray, Optimizations and other modifications are not enabled.
The use of cfmutablearrayref in Objective-c is faster, because in very many cases you don't have to keep that string.
Add an integer to an array (Append native integer to native array)
Swift:6.51s
Objective-c: 0.023s (283x faster)
The SWIFT code uses an array of integers of type int. Objective-c used NSNumber and Nsmutablearray.
Stitching string (concatenate-strings)
Swift:3.47s
Objective-c: 0.27s (21x faster)
Swift Internal Loop Code:
TheString3 = thestring + theString2
Objective-c Internal Loop Code:
TheString3 = [TheString stringbyappendingstring:thestring2];
Instead, swift or newborn. Need to be tested by developers.
A sensible strategy might be for existing projects, keep using objective C. And for new projects, try using Swift,
And let the development team follow the development of Swift language, learning at any time.
Many other swift real-time information can techbrood Swift.
by Iefreer
Swift,objective-c Language Performance Control test