This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //: Playground - noun: a place where people can play | |
| import Foundation | |
| var str = "Hello, playground" | |
| func check(p1 : [Double], _ p2 : [Double]) { | |
| assert(p1.count == p2.count, "Vectors are of different size") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NameIndex { | |
| Group observedCollection; | |
| Dictionary<string, Entity> lookup = new Dictionary<string, Entity>(); | |
| public NameIndex(Pool pool){ | |
| observedCollection = pool.GetGroup(Matcher.Name); | |
| observedCollection.OnEntityAdded += AddEntity; | |
| observedCollection.OnEntityRemoved += RemoveEntity; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| var machines : [NSURL] = [] | |
| var numberOfTicks = 0 | |
| let loadingQueues = [ // 4 cores -> 4 queues, more cores -> add more queues | |
| dispatch_queue_create("loadingQueue1", nil), | |
| dispatch_queue_create("loadingQueue2", nil), | |
| dispatch_queue_create("loadingQueue3", nil), | |
| dispatch_queue_create("loadingQueue4", nil), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Person1 { | |
| var name : String? | |
| } | |
| class Person2 { | |
| var name : String? | |
| } | |
| var people1 = Array.init(count: 10, repeatedValue: Person1()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "location":"http://google.com/flatbuffers/", | |
| "initialized":true, | |
| "fruit":"Bananas", | |
| "list":[ | |
| { | |
| "sibling":{ | |
| "parent":{ | |
| "i_d":0xABADCAFE, | |
| "count":10000, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "location":"http://google.com/flatbuffers/", | |
| "initialized":true, | |
| "fruit":"Bananas", | |
| "list":[ | |
| { | |
| "sibling":{ | |
| "parent":{ | |
| "i_d":0xABADCAFE, | |
| "count":10000, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private func fromByteArray<T : Scalar>(buffer : UnsafePointer<UInt8>, _ position : Int) -> T{ | |
| return UnsafePointer<T>(buffer.advancedBy(position)).memory | |
| } | |
| private func getPropertyOffset(buffer : UnsafePointer<UInt8>, _ objectOffset : Offset, propertyIndex : Int)->Int { | |
| let offset = Int(objectOffset) | |
| let localOffset : Int32 = fromByteArray(buffer, offset) | |
| let vTableOffset : Int = offset - Int(localOffset) | |
| let vTableLength : Int16 = fromByteArray(buffer, vTableOffset) | |
| if(vTableLength<=Int16(4 + propertyIndex * 2)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct FooBarStruct { | |
| var buffer : UnsafePointer<UInt8> = nil | |
| var myOffset : Offset = 0 | |
| var name: UnsafeBufferPointer<UInt8> { get { return getStringBuffer(buffer, getOffset(buffer, myOffset, propertyIndex: 1))! } } | |
| var rating: Float64 { get { return get(buffer, myOffset, propertyIndex: 2)! } } | |
| var postfix: UInt8 { get { return get(buffer, myOffset, propertyIndex: 3)! } } | |
| var sibling: Bar { get { return get(buffer, myOffset, propertyIndex: 0)! } } | |
| } | |
| struct FooBarContainerStruct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func runbench(lazyrun: BooleanType) | |
| { | |
| var encode = 0.0 | |
| var decode = 0.0 | |
| var direct = 0.0 | |
| var use = 0.0 | |
| var dealloc = 0.0 | |
| var withStruct = 0.0 | |
| var total:UInt64 = 0 | |
| var total1:UInt64 = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| { |