Skip to content

Instantly share code, notes, and snippets.

View duarten's full-sized avatar
🤷‍♂️

Duarte Nunes duarten

🤷‍♂️
View GitHub Profile
@duarten
duarten / BenchmarkIterateAndClear.java
Created July 27, 2014 14:49
Iterating and clearing
import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
@duarten
duarten / HashMapBenchmark.java
Created October 30, 2014 18:33
Concurrent maps benchmarks
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import scala.collection.concurrent.TrieMap;
import org.openjdk.jmh.annotations.*;
@BenchmarkMode(Mode.AverageTime)

Rich Hickey on becoming a better developer

Rich Hickey • 3 years ago

Sorry, I have to disagree with the entire premise here.

A wide variety of experiences might lead to well-roundedness, but not to greatness, nor even goodness. By constantly switching from one thing to another you are always reaching above your comfort zone, yes, but doing so by resetting your skill and knowledge level to zero.

Mastery comes from a combination of at least several of the following:

@duarten
duarten / agent.cpp
Created March 4, 2015 23:52
Java JVMTI Agent
#include <jvmti.h>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef struct {
jvmtiEnv *jvmti;
} GlobalAgentData;
@duarten
duarten / Misaligned.java
Created March 6, 2015 09:43
Misaligned accesses
package org.openjdk;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.CompilerControl;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
@duarten
duarten / latency.txt
Last active August 29, 2015 14:17 — forked from jboner/latency.txt
Latency Comparison Numbers
--------------------------
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
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@duarten
duarten / vbr.s
Created May 14, 2015 14:27
A simple vbr
.equ START_OFFSET, 0x7c00
.equ STACK_TOP, START_OFFSET - 22
.equ VAR_BASE, START_OFFSET - 22
.equ DISK_ADDRESS_PACKET_OFFSET, 0
.equ PACKET_SIZE_OFFSET, 0
.equ SECTORS_TO_TRANSFER_OFFSET, 2
.equ TRANSFER_BUFFER_ADDR_OFFSET, 4
.equ TRANSFER_BUFFER_SEG_OFFSET, 6
.equ STARTING_SECTOR_OFFSET, 8
@duarten
duarten / lazy_value.cc
Last active June 20, 2016 11:06
A lazy value implementation in C++
#include <iostream>
#include <functional>
template<typename T>
class lazy_value {
union {
std::function<T()> _f;
mutable T _value;
};
mutable T& (*_thunk)(const lazy_value&);
@duarten
duarten / buckets.cc
Created August 4, 2016 23:56
HdrHistogram-style bucketing
#include <x86intrin.h>
#include <iostream>
#include <limits>
#include <array>
constexpr int segment_size_shift = 18; // 256K
constexpr size_t segment_size = 1 << segment_size_shift;
using size_type = uint32_t;
constexpr size_type initial_buckets_shift = 4;
@duarten
duarten / type_classes.cc
Created October 18, 2016 21:35
Type classes in C++
#include <iostream>
#include <vector>
template<typename T>
struct my_traits {
void m();
};
template<>
struct my_traits<int> {