Skip to content

Instantly share code, notes, and snippets.

@tomquist
tomquist / StringPerformanceTest.swift
Last active Apr 3, 2019
Compare performance of iterating through a UTF8View of a 79 bytes String with iterating through its Data representation.
View StringPerformanceTest.swift
// 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
Decoding heterogeneous array in swift
View Decode.swift
import Foundation
struct User {
let name: String
let age: Int
}
struct Car {
let color: String
}
View LOOCryptString.h
//
// 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 Jun 11, 2014
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console