Files
swift-mirror/utils/benchmark/LinkedList/link.swift
Nadav Rotem 773692a7de Add a test program that allocates and sums the first 1M elements in a linked list.
We beat python by only 2x, but we can add a few peepholes to Optional and reduce the list size to make sure we are not memory bound.


Swift SVN r16575
2014-04-20 02:14:44 +00:00

31 lines
546 B
Swift

@asmname("mach_absolute_time") func __mach_absolute_time__() -> UInt64
@final class Node {
var next : Optional<Node>
var data : Int
init(n : Optional<Node>, d : Int) {
next = n
data = d
}
}
print("Creating list\n")
var head = Node(nil, 0)
for i in 0...1000000 {
head = Node(head, i)
}
let start = __mach_absolute_time__()
print("Summing list\n")
var sum = 0
while let nxt = head.next {
sum += head.data
head = nxt
}
let delta = __mach_absolute_time__() - start
print("sum = \(sum)\n")
println("\(delta) nanoseconds.")