Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Jiacai Liu jiacai2050

🎯
Focusing
Block or report user

Report or block jiacai2050

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View unsafe_string_to_bytes.go
import (
"encoding/binary"
"github.com/spaolacci/murmur3"
)
func UnsafeToBytes(s string) []byte {
return *(*[]byte)(unsafe.Pointer(&s))
}
@jiacai2050
jiacai2050 / defer_benchmank.go
Last active Sep 10, 2019
go defer benchmark 1.12 vs 1.13
View defer_benchmank.go
package defer_demo
import (
"testing"
)
func doDefer() int {
acc := 0
for i := 0; i < 100; i++ {
defer func(i int) {
View my-debug.md

I write a buggy server to leak socket fd, which listen on 5000, and as expected there were CLOSE-WAIT left when client is closed

$ ss -ntpa | grep 5000
LISTEN     0      50                       :::5000                    :::*      users:(("java",14586,92))
CLOSE-WAIT 79     0          ::ffff:127.0.0.1:5000      ::ffff:127.0.0.1:55804  users:(("java",14586,96))
CLOSE-WAIT 79     0          ::ffff:127.0.0.1:5000      ::ffff:127.0.0.1:59235  users:(("java",14586,93))
CLOSE-WAIT 5      0          ::ffff:127.0.0.1:5000      ::ffff:127.0.0.1:55803  users:(("java",14586,95))
CLOSE-WAIT 150    0          ::ffff:127.0.0.1:5000      ::ffff:127.0.0.1:59236  users:(("java",14586,94))
View CacheLineEffect.java
package benchmark;
public class CacheLineEffect {
//考虑一般缓存行大小是64字节,一个 long 类型占8字节
static long[][] arr;
public static void main(String[] args) {
arr = new long[1024 * 1024][];
for (int i = 0; i < 1024 * 1024; i++) {
arr[i] = new long[8];
View hystrix_circuit_bug.java
package hystrix;
import com.netflix.hystrix.*;
import rx.Observable;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
View specter-benchmark.clj
(ns demo.specter-benchmark
(:use [com.rpl.specter]
[criterium.core]))
;; one big app state, look like
;; {app-id1 {peer-id1 #{ch-di1}}}
(def clients (atom {}))
(def num-app 10)
(def num-peer 20)
View trrprefs.md

Preferences

All preferences for the DNS-over-HTTPS functionality in Firefox are located under the "network.trr" prefix (TRR == Trusted Recursive Resolver).

network.trr.mode

set which resolver mode you want.

0 - Off (default). use standard native resolving only (don't use TRR at all)

1 - Race native against TRR. Do them both in parallel and go with the one that returns a result first.

View transducer_bench.clj
(def dataset (interleave (range 10000000) (range)))
(defn workflow [ds]
(->> ds
(dedupe)
(map #(* % %))
(filter #(= 0 (rem % 111)))
(take 10)))
View map_defrecord_bench.clj
(ns demo.record
(:require [criterium.core :refer [bench with-progress-reporting]]))
(def a-z-ks (map (comp keyword str) (seq "abcdefghijklmnopqrstuwvxyz")))
(def dummy-map (zipmap a-z-ks (range)))
(defmacro alphabet-macro []
`(do
(defrecord ~'Alphabet [~@(map (comp symbol str) a-z-ks)])
(def ~'dummy-record (~'Alphabet. ~@(range 26)))))
@jiacai2050
jiacai2050 / CacheTest.java
Created Sep 6, 2017
guava caffeine 性能测试
View CacheTest.java
import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.yahoo.ycsb.generator.NumberGenerator;
import com.yahoo.ycsb.generator.ScrambledZipfianGenerator;
import junit.framework.TestCase;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.text.NumberFormat;
You can’t perform that action at this time.