Skip to content

Instantly share code, notes, and snippets.

View ClarkThan's full-sized avatar
😇

Clark Than ClarkThan

😇
View GitHub Profile
@ClarkThan
ClarkThan / algo1.py
Last active November 24, 2018 03:21
一个无序大数组,相邻元素都不同,随便找出一个比左右相邻元素都小的元素的位置(如果是最两侧的元素,只要小于相邻元素也算)
# -*- coding: utf-8 -*-
ls1 = list(range(1000000)); ls1[0:3] = [1,0,1]
ls2 = list(range(1000000, 3000, -1)) + list(range(3000))
def find_index(lst):
"""
一个无序大数组,相邻元素都不同,找出一个比左右相邻元素都小的元素的位置(如果是最两侧的元素,只要小于相邻元素也算)
按照约定条件给出的参数数组,可以判断出数组中一定存在目标元素。
@ClarkThan
ClarkThan / Quirks of C.md
Created June 13, 2022 09:20 — forked from fay59/Quirks of C.md
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;
@ClarkThan
ClarkThan / latency.txt
Created June 13, 2022 09:23 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@ClarkThan
ClarkThan / tucan_bibliography.md
Created July 13, 2022 04:53 — forked from mrnugget/tucan_bibliography.md
Tucan Bibliography. Majority of the resources I used to build Tucan, my toy optimizing compiler in Rust

Tucan - Bibliography

Majority of the resources I used to build Tucan, my toy optimizing compiler in Rust. This list is not complete but most of the things listed here are things I really read through and used.

Books

  • Engineering a compiler (I use this a lot! For SSA, dominance and optimizations)
  • [Static Single Assignment Book][ssabook] (I use this a lot!)
  • Types And Programming Languages
@ClarkThan
ClarkThan / lib.rs
Created August 7, 2022 08:25 — forked from Measter/lib.rs
Rust Perf Benchmark
#![feature(test)]
extern crate test;
#[cfg(test)]
mod tests {
use super::*;
use std::fs::{File};
use std::io::{BufWriter, Write, BufRead, BufReader};
#[bench]
@ClarkThan
ClarkThan / CoC.ml
Created December 13, 2022 09:24 — forked from Hirrolot/CoC.ml
Barebones lambda cube in OCaml
type binder = Lam | Pi
(* The syntax of our calculus. Notice that types are represented in the same way
as terms, which is the essence of CoC. *)
type term =
| Var of string
| Appl of term * term
| Binder of binder * string * term * term
| Star
| Box
@ClarkThan
ClarkThan / binned_allocator.zig
Created February 3, 2023 04:37 — forked from silversquirl/binned_allocator.zig
A fast, simple allocator for Zig
const std = @import("std");
const builtin = @import("builtin");
pub const Config = struct {
/// Whether to synchronize usage of this allocator.
/// For actual thread safety, the backing allocator must also be thread safe.
thread_safe: bool = !builtin.single_threaded,
/// Whether to warn about leaked memory on deinit.
/// This reporting is extremely limited; for proper leak checking use GeneralPurposeAllocator.
#include <iostream>
#ifdef __AVX__
#include <immintrin.h>
#else
#warning No AVX support - will not compile
#endif
int main(int argc, char **argv)
{