[swift-evolution] [Proposal] Add .order() family of methods to Collection

Milos Rankovic milos at milos-and-slavica.net
Mon Apr 11 15:06:07 CDT 2016


> On 11 Apr 2016, at 20:47, Taras Zakharko <taras.zakharko at uzh.ch <mailto:taras.zakharko at uzh.ch>> wrote:
> 
> the question is what is faster: {self[0] < self[1]} or {$1.0 < $1.1}

Yes, you are right that this is in fact not obvious! 

I’ve just measured and, though my implementation is faster, it’s advantage only grows linearly with the length of the array:

	
	let a = (1...100_000).shuffled
	
	func testPerformanceOf_orderSequence() {
		self.measureBlock {
			self.a.orderSequence(<) // 0.464 sec
		}
	}
	
	func testPerformanceOf_orderCollection() {
		self.measureBlock {
			self.a.orderCollection(<) // 1.067 sec
		}
	}

It remains only twice as fast for 10,000 and 1000 elements (below that is the margin of error).

milos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160411/5c16d5c7/attachment.html>


More information about the swift-evolution mailing list