Skip to content

Instantly share code, notes, and snippets.

@mzaks
mzaks / APL.swift
Created February 11, 2016 15:48
Subset of APL written in Swift
//: 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")
}
@mzaks
mzaks / NameIndex.cs
Last active September 20, 2018 16:20
Example of an index in Entitas-CSharp
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;
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),
@mzaks
mzaks / ArrayWitRepeatedValue.swift
Last active April 28, 2016 10:26
Difference between Value and Reference type
struct Person1 {
var name : String?
}
class Person2 {
var name : String?
}
var people1 = Array.init(count: 10, repeatedValue: Person1())
@mzaks
mzaks / benchamark.json
Created May 15, 2016 21:53
FlatBuffers Benchmark data as JSON
{
"location":"http://google.com/flatbuffers/",
"initialized":true,
"fruit":"Bananas",
"list":[
{
"sibling":{
"parent":{
"i_d":0xABADCAFE,
"count":10000,
@mzaks
mzaks / benchamark.json
Last active May 15, 2016 21:53
FlatBuffers Benchmark data as JSON
{
"location":"http://google.com/flatbuffers/",
"initialized":true,
"fruit":"Bananas",
"list":[
{
"sibling":{
"parent":{
"i_d":0xABADCAFE,
"count":10000,
@mzaks
mzaks / bench_functions.swift
Created May 15, 2016 22:27
Decoding FlatBuffers with bare functions
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)) {
@mzaks
mzaks / bench_structs.swift
Created May 15, 2016 22:38
Decoding FlatBuffers with struct API
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 {
@mzaks
mzaks / updated_run_bench.swift
Created May 17, 2016 13:53
Updated the run bench to have 3 distinct total counters for different type of decode+traverse+dealloc
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
@mzaks
mzaks / updated_run_bench2.swift
Created May 17, 2016 15:10
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
{