Skip to content

Instantly share code, notes, and snippets.

View PatrickPijnappel's full-sized avatar

Patrick Pijnappel PatrickPijnappel

View GitHub Profile
+0x00 pushq %rbp
+0x01 movq %rsp, %rbp
+0x04 pushq %r15
+0x06 pushq %r14
+0x08 pushq %r13
+0x0a pushq %r12
+0x0c pushq %rbx
+0x0d subq $88, %rsp
+0x11 imulq $4, %rdi, %r14
+0x15 jo "Swift runtime failure: arithmetic overflow"
<unknown>:0: error: fatal error encountered while reading from module 'Foundation'; please file a bug report with your project and the crash log
<unknown>:0: note: compiling as Swift 4.1.50, with 'Foundation' built as Swift 5.3 (this is supported but may expose additional compiler issues)
*** DESERIALIZATION FAILURE (please include this section in any bug report) ***
top-level value not found
Cross-reference to module 'Darwin'
... memcpy
... with type (Optional<UnsafeMutableRawPointer>, Optional<UnsafeRawPointer>, Int) -> Optional<UnsafeMutableRawPointer>
Stack dump:
Started listener
Incoming connection
2019-07-12 23:22:25.572943+1000 TestApp[4232:3163704] Received packet: 0
2019-07-12 23:22:25.573490+1000 TestApp[4232:3163705] Received packet: 0
2019-07-12 23:22:25.573913+1000 TestApp[4232:3163705] Received packet: 0
2019-07-12 23:22:25.574526+1000 TestApp[4232:3163705] Received packet: 0
2019-07-12 23:22:25.575218+1000 TestApp[4232:3163705] Received packet: 0
2019-07-12 23:22:25.575738+1000 TestApp[4232:3163705] Received packet: 0
2019-07-12 23:22:25.576262+1000 TestApp[4232:3163705] Received packet: 0
2019-07-12 23:22:25.576876+1000 TestApp[4232:3163704] Received packet: 0
@PatrickPijnappel
PatrickPijnappel / ViewController.swift
Last active October 10, 2021 07:31
Network Lag STR
import UIKit
import Network
class ViewController: UIViewController {
var server: Server?
var client: Client?
override func viewDidLoad() {
super.viewDidLoad()
if UIDevice.current.userInterfaceIdiom == .pad {
@PatrickPijnappel
PatrickPijnappel / NewUTF.swift
Last active July 7, 2016 03:57
UTF decode benchmark
/// A codec for translating between Unicode scalar values and UTF-8 code
/// units.
public struct NewUTF8 : _UnicodeCodec {
// See Unicode 8.0.0, Ch 3.9, UTF-8.
// http://www.unicode.org/versions/Unicode8.0.0/ch03.pdf
/// A type that can hold code unit values for this encoding.
public typealias CodeUnit = UInt8
@PatrickPijnappel
PatrickPijnappel / main.swift
Created March 20, 2016 03:37
UTF8 Comparison
import Foundation
/// A codec for [UTF-8](http://www.unicode.org/glossary/#UTF_8).
public struct OldUTF8 {
// See Unicode 8.0.0, Ch 3.9, UTF-8.
// http://www.unicode.org/versions/Unicode8.0.0/ch03.pdf
/// A type that can hold [code unit](http://www.unicode.org/glossary/#code_unit) values for this
/// encoding.
@PatrickPijnappel
PatrickPijnappel / New.sil.c
Last active December 17, 2015 04:02
SIL Comparison min() refactor
// Generated with:
// $ swiftc -O -emit-sil New.swift -o New.sil.c
// main.min2 <A where A: Swift.Comparable> (A, A) -> A
sil @_TF4main4min2uRq_Ss10Comparable_FTq_q__q_ : $@convention(thin) <T where T : Comparable> (@out T, @in T, @in T) -> () {
bb0(%0 : $*T, %1 : $*T, %2 : $*T):
debug_value_addr %1 : $*T // let x // id: %3
debug_value_addr %2 : $*T // let y // id: %4
%5 = witness_method $T, #Comparable."<"!1 : $@convention(witness_method) <τ_0_0 where τ_0_0 : Comparable> (@in τ_0_0, @in τ_0_0, @thick τ_0_0.Type) -> Bool // user: %11
%6 = metatype $@thick T.Type // user: %11
@PatrickPijnappel
PatrickPijnappel / ZipNew.sil.c
Last active December 13, 2015 08:47
Zip tuple expansion comparison
// Zip2.Zip2Sequence.init <A, B where A: Swift.SequenceType, B: Swift.SequenceType> (Zip2.Zip2Sequence<A, B>.Type)(A, B) -> Zip2.Zip2Sequence<A, B>
sil @_TFV4Zip212Zip2SequenceCu0_Rq_Ss12SequenceTypeq0_S1__fMGS0_q_q0__FTq_q0__GS0_q_q0__ : $@convention(thin) <Sequence1, Sequence2 where Sequence1 : SequenceType, Sequence2 : SequenceType, Sequence1.Generator : GeneratorType, Sequence2.Generator : GeneratorType> (@out Zip2Sequence<Sequence1, Sequence2>, @in Sequence1, @in Sequence2, @thin Zip2Sequence<Sequence1, Sequence2>.Type) -> () {
bb0(%0 : $*Zip2Sequence<Sequence1, Sequence2>, %1 : $*Sequence1, %2 : $*Sequence2, %3 : $@thin Zip2Sequence<Sequence1, Sequence2>.Type):
%4 = alloc_stack $Zip2Sequence<Sequence1, Sequence2> // var self // users: %7, %9, %11, %12, %14
debug_value_addr %1 : $*Sequence1 // let sequence1 // id: %5
debug_value_addr %2 : $*Sequence2 // let sequence2 // id: %6
%7 = struct_element_addr %4#1 : $*Zip2Sequence<Sequence1, Sequence2>, #Zip2Sequence._sequence1 // user: %8
copy_add
@PatrickPijnappel
PatrickPijnappel / New.sil.c
Created December 12, 2015 03:54
Zip2Generator.next() SIL comparison
// main.Zip2GeneratorNew.next <A, B where A: Swift.GeneratorType, B: Swift.GeneratorType> (inout main.Zip2GeneratorNew<A, B>)() -> Swift.Optional<(A.Element, B.Element)>
sil @_TFV4main16Zip2GeneratorNew4nextu0_Rq_Ss13GeneratorTypeq0_S1__fRGS0_q_q0__FT_GSqTqq_S1_7Elementqq0_S1_7Element__ : $@convention(method) <Generator1, Generator2 where Generator1 : GeneratorType, Generator2 : GeneratorType> (@out Optional<(Generator1.Element, Generator2.Element)>, @inout Zip2GeneratorNew<Generator1, Generator2>) -> () {
bb0(%0 : $*Optional<(Generator1.Element, Generator2.Element)>, %1 : $*Zip2GeneratorNew<Generator1, Generator2>):
%2 = struct_element_addr %1 : $*Zip2GeneratorNew<Generator1, Generator2>, #Zip2GeneratorNew._reachedEnd // users: %3, %53
%3 = struct_element_addr %2 : $*Bool, #Bool.value // user: %4
%4 = load %3 : $*Builtin.Int1 // user: %5
cond_br %4, bb1, bb2 // id: %5
bb1: // Preds: bb0
import XCTest
class Benchmark: XCTestCase {
let count = 500_000_000
func testPerformance1() {
measureBlock {
var total = 0
let a = Repeat(count: self.count, repeatedValue: 3)