Skip to content

Instantly share code, notes, and snippets.

View tomquist's full-sized avatar

Tom Quist tomquist

View GitHub Profile
@tomquist
tomquist / StringPerformanceTest.swift
Last active April 3, 2019 16:49
Compare performance of iterating through a UTF8View of a 79 bytes String with iterating through its Data representation.
// Executed with optimization -Os on a MacBook Pro (15-inch, 2017) 2,8 GHz Intel Core i7
class StringPerformanceTest: XCTestCase {
// Takes in average 0.075 secs
func testPerformanceOfUTF8View() {
let data = "_cqeFf~cjVf@p@fA}AtAoB`ArAx@hA`GbIvDiFv@gAh@t@X\\|@z@`@Z\\Xf@Vf@VpA\\tATJ@NBBkC".data(using: .utf8)!
let string = String(decoding: data, as: UTF8.self)
measure {
for _ in 0...10_000 {
_ = string.utf8.reduce(into: 0, { count, _ in count += 1 })
@tomquist
tomquist / Decode.swift
Last active May 9, 2016 02:40
Decoding heterogeneous array in swift
import Foundation
struct User {
let name: String
let age: Int
}
struct Car {
let color: String
}
//
// LOOCryptString.h
//
// Created by Marcin Swiderski on 6/8/12.
// Copyright (c) 2012 Marcin Swiderski. All rights reserved.
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
@tomquist
tomquist / 0_reuse_code.js
Created June 11, 2014 20:05
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console