Skip to content

Instantly share code, notes, and snippets.

View jackluson's full-sized avatar
🎯
Focusing

Jack Lu jackluson

🎯
Focusing
  • AnchorData
  • china
View GitHub Profile
@jackluson
jackluson / latency.markdown
Created December 10, 2024 08:33 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@jackluson
jackluson / latency.txt
Created December 10, 2024 08:32 — 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
@jackluson
jackluson / output_webstream.ts
Created November 22, 2023 14:14
output Web stream to a file in nodejs
import {
WritableStream
} from 'node:stream/web';
import fs from 'fs'
// https://stackoverflow.com/questions/73338326/how-can-i-save-a-file-i-download-using-fetch-with-fs/73338676#73338676
const object = await getObject(file.filename)
const download_write_stream = fs.createWriteStream(file.filename);
@jackluson
jackluson / delete_git_submodule.md
Created November 14, 2022 13:49 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@jackluson
jackluson / logging different threads to different files
Created April 16, 2022 14:44
logging different threads to different files
import logging
from threading import Thread
device_ids = ["d1","d2","d3"]
threads = []
def get_logger(name, log_file, level=logging.INFO):
handler = logging.FileHandler(log_file)
formatter = logging.Formatter('[line:%(lineno)d] - %(levelname)s: %(message)s')
handler.setFormatter(formatter)
logger = logging.getLogger(name)
@jackluson
jackluson / react modal
Last active November 11, 2021 05:08
Modal with react
import ReactDOM from 'react-dom';
import { useEffect } from 'react';
Modal._PortalStack = [] // 利用栈结构管理多个弹窗面板
function Modal(Component) {
function Portal(props?: any) {
useEffect(() => {
document.body.appendChild(Portal._container);
return () => {