Skip to content

Instantly share code, notes, and snippets.

@okumura
okumura / mw32getpeb.c
Last active January 31, 2024 09:57
Get PEB for Windows.
LPVOID mw32GetPeb() {
#if defined(_WIN64)
UINT64 uiPeb = __readgsqword(0x60);
return (LPVOID) (UINT_PTR) uiPeb;
#else
UINT32 uiPeb = __readfsdword(0x30);
return (LPVOID) (UINT_PTR) uiPeb;
#endif
}
@okumura
okumura / wc-mp-pool.py
Created November 24, 2019 22:50
wc -l
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import multiprocessing
import os
import sys
import time
import threading
(a) time (b) time (c) time (d) time (e) time (a) mem (b) mem (c) mem (d) mem (e) mem
large-file-1mb.txt 0 0.01 0.01 0.14 0.04 1868 7376 6220 11832 12552
large-file-10mb.txt 0 0.02 0.01 0.14 0.04 1824 18124 6316 11828 12744
large-file-100mb.txt 0.02 0.12 0.06 0.14 0.07 1780 128160 6356 11776 12816
large-file-1gb.txt 0.19 1.75 0.54 0.24 0.2 1872 1235448 6360 11684 12732
(a) time (b) time (c) time (d) time (e) time (a) mem (b) mem (c) mem (d) mem (e) mem
large-file-1mb.txt 0 0.03 0.01 0.17 0.07 1868 9428 7664 14892 15368
large-file-10mb.txt 0 0.04 0.02 0.16 0.07 1780 27784 7672 14944 15536
large-file-100mb.txt 0.01 0.29 0.08 0.16 0.1 1876 213252 7696 15056 15408
large-file-1gb.txt 0.18 13.09 0.66 0.26 0.25 1856 1911580 7704 15112 15396
@okumura
okumura / wc-py-result.csv
Created November 24, 2019 23:25
wc-l python benchmark
(a) time (b) time (c) time (d) time (e) time (a) mem (b) mem (c) mem (d) mem (e) mem
large-file-1mb.txt 0 0.01 0.01 0.14 0.04 1868 7376 6220 11832 12552
large-file-10mb.txt 0 0.02 0.01 0.14 0.04 1824 18124 6316 11828 12744
large-file-100mb.txt 0.02 0.12 0.06 0.14 0.07 1780 128160 6356 11776 12816
large-file-1gb.txt 0.19 1.75 0.54 0.24 0.2 1872 1235448 6360 11684 12732
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import multiprocessing
import os
import sys
import time
import threading
import concurrent.futures as futures
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def wc_block_64k(name, blocksize=65536):
def blocks(f):
while True:
b = f.read(blocksize)
@okumura
okumura / wc-naive.py
Created November 24, 2019 22:49
wc -l
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def wc_naive(name):
with open(name, 'r') as f:
return sum(1 for line in f)
@okumura
okumura / map_clsloc.txt
Created January 29, 2018 09:10 — forked from aaronpolhamus/map_clsloc.txt
Image net classes + labels
n02119789 1 kit_fox
n02100735 2 English_setter
n02110185 3 Siberian_husky
n02096294 4 Australian_terrier
n02102040 5 English_springer
n02066245 6 grey_whale
n02509815 7 lesser_panda
n02124075 8 Egyptian_cat
n02417914 9 ibex
n02123394 10 Persian_cat
@okumura
okumura / mw32getpebldrdata.c
Created October 26, 2013 19:49
Get PEB_LDR_DATA for Windows.
typedef struct PEB_LDR_DATA {
ULONG Length;
BOOLEAN Initialized;
PVOID SsHandle;
LIST_ENTRY InLoadOrderModuleList;
LIST_ENTRY InMemoryOrderModuleList;
LIST_ENTRY InInitializationOrderModuleList;
} PEB_LDR_DATA, *PPEB_LDR_DATA;
PPEB_LDR_DATA mw32GetPebLdrData() {