Skip to content

Instantly share code, notes, and snippets.

@mzaks
Created May 17, 2016 15:10
Show Gist options
  • Select an option

  • Save mzaks/eeeaaa45f230e45299cc7f044a930edc to your computer and use it in GitHub Desktop.

Select an option

Save mzaks/eeeaaa45f230e45299cc7f044a930edc to your computer and use it in GitHub Desktop.
Passing in start to the benchmark function
let time11 = CFAbsoluteTimeGetCurrent()
for i in 0..<iterations {
let result = flatuseStruct(outputData, start:i)
assert(result == 8644311666 + Int(i))
total2 = total2 + UInt64(result)
}
let time12 = CFAbsoluteTimeGetCurrent()
func flatuseStruct(buffer : UnsafePointer<UInt8>, start : UInt) -> Int
{
var sum:Int = Int(start)
// this struct or copies of it are only valid as long as pointer
// to the underlying data is valid
// should use createInstance() for a long-term usable mutable object instance
// if needed, but the struct interface is good for lazy stream processing
var foobarcontainer = FooBarContainer.Fast(buffer)
sum = sum + Int(foobarcontainer.location!.count)
sum = sum + Int(foobarcontainer.fruit!.rawValue)
sum = sum + (foobarcontainer.initialized ? 1 : 0)
let list = foobarcontainer.list
for i in 0..<list.count {
let foobar = list[i]!
sum = sum + Int(foobar.name!.count)
sum = sum + Int(foobar.postfix)
sum = sum + Int(foobar.rating)
let bar = foobar.sibling!
sum = sum + Int(bar.ratio)
sum = sum + Int(bar.size)
sum = sum + Int(bar.time)
let foo = bar.parent
sum = sum + Int(foo.count)
sum = sum + Int(foo.i_d)
sum = sum + Int(foo.length)
sum = sum + Int(foo.prefix)
}
return sum
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment