Skip to content

Instantly share code, notes, and snippets.

View killme2008's full-sized avatar
🎯
Focusing

dennis zhuang killme2008

🎯
Focusing
View GitHub Profile
@killme2008
killme2008 / Test.java
Created February 18, 2017 07:29
Test
public class Test {
private static int plusOne(int i) {
return ++i;
}
private static long oneForMethod(int x, int times) {
long start = System.nanoTime();
for (int i = 0; i < times; i++) {
@killme2008
killme2008 / ping_pong.ex
Last active January 6, 2017 06:43
Erlang process context switch test.
defmodule PingPong do
def test(n, m) do
parent = self()
spawn fn ->
s = :erlang.monotonic_time(:microsecond)
{cs1,_} = :erlang.statistics(:context_switches)
{r1, _} = :erlang.statistics(:reductions)
first = self()
last = start(first, n, m)
@killme2008
killme2008 / test-delay.clj
Created November 29, 2016 07:54
Clojure delay benchmark
(ns test-delay
(:import [java.util.concurrent CyclicBarrier]))
(defn benchmark-delay [threads]
(let [n (rand-int 100)
d (delay (inc n))
ret (inc n)
^CyclicBarrier barrier (CyclicBarrier. (+ threads 1))]
(dotimes [_ threads]
(->
@killme2008
killme2008 / clean_branch.sh
Created October 28, 2016 07:00
A shell to clean git branches in the form of "feature/yyyy.mm.dd"
cyear=$(date +"%Y")
cmonth=$(date +"%m")
cday=$(date +"%d")
isnum() { awk -v a="$1" 'BEGIN {print (a == a + 0)}'; }
for b in `git branch`
do
if [[ $b == feature/201* ]];
then
@killme2008
killme2008 / BusyLock.java
Created July 24, 2016 04:42
高速缓存对自旋锁的影响
package net.fnil.java8_examples;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicInteger;
public class BusyLock {
private int count;
private AtomicInteger state;
@killme2008
killme2008 / FalseSharing.java
Created July 20, 2016 07:53
Java False sharing test
public class FalseSharing implements Runnable {
public final static int NUM_THREADS = 4; // change
public final static long ITERATIONS = 500L * 1000L * 1000L;
private final int arrayIndex;
private static VolatileLong3[] longs = new VolatileLong3[NUM_THREADS];
static {
for (int i = 0; i < longs.length; i++) {
longs[i] = new VolatileLong3();
@killme2008
killme2008 / L1CacheMiss.java
Created July 20, 2016 07:48
java L1 cache miss test
public class L1CacheMiss {
private static final int RUNS = 10;
private static final int DIMENSION_1 = 1024 * 1024;
private static final int DIMENSION_2 = 62;
private static long[][] longs;
public static void main(String[] args) throws Exception {
Thread.sleep(10000);
longs = new long[DIMENSION_1][];
@killme2008
killme2008 / ip_range.clj
Created June 29, 2016 03:33
Check private range ip in clojure
(defn- get-ip-num [^String ip]
(when ip
(when-let [groups (re-matches #"^(\d+)\.(\d+)\.(\d+)\.(\d+)$" ip)]
(let [[a b c d] (map #(Integer/valueOf ^String %) (next groups))]
(+
(* 256 256 256 a)
(* 256 256 b)
(* 256 c)
d)))))
@killme2008
killme2008 / method_missing.patch
Last active June 27, 2016 18:02
Method missing patch for clojure compiler
From d918ba819dc67d9977c3a13c1d3ac16e46e02dc4 Mon Sep 17 00:00:00 2001
From: dennis zhuang <killme2008@gmail.com>
Date: Tue, 28 Jun 2016 00:30:16 +0800
Subject: [PATCH] Patch Compiler#resolveIn to introduce method_missing
---
src/jvm/clojure/lang/Compiler.java | 23 ++++++++++++++++++++---
src/jvm/clojure/lang/Var.java | 9 +++++++++
2 files changed, 29 insertions(+), 3 deletions(-)
@killme2008
killme2008 / method_missing.clj
Last active June 21, 2016 09:12
Method missing in clojure
;;namespace test
(ns missing-test)
(defn method-missing [func args]
(println "missing '" func "' with args:" args)
[func args])
(defn hello [name]
(str "hello," name))