Skip to content

Instantly share code, notes, and snippets.

@markshannon
markshannon / 1000.md
Created October 7, 2024 14:25
1000 threads experiment

Case 1 -- Ultra contended

from threading import Thread
import time

class Counter():

    def __init__(self):
        self._counter = 0
commit be741bcbc978520403c401b6ab6d2196ebe7971d
Author: Mark Shannon <[email protected]>
Date: Thu Nov 16 10:49:06 2023 +0000
Reorganize code gen
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 587efc9268a..dcc2cb05ac9 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
op(_BINARY_OP_ADD_INT, (unused/1, left, right -- res)) {
if (IS_CONST(left) && IS_CONST(right)) {
res = MAKE_CONST(Py_NumberAdd(left->value, right->value));
emit(_LOAD_CONST_INLINE, res->value);
}
else {
res = UNKNOWN();
emit(_BINARY_OP_ADD_INT);
}
Py_DECREF(left);
import timeit
import sys
def foo():
for i in range(100_000):
if i == 50_000:
pass # Put breakpoint here
print("No debug")
class CallsLeave:
def __init__(self, cls, obj):
self.cls = cls
self.obj = obj
def __call__(self, exc, val, tb):
self.cls.__leave__(self.obj, val)
class CallsLeaveDescriptor:

Results vs. base

  • fork: carljm
  • ref: inlinecomp2
  • machine: linux-x86_64
  • commit hash: 36b2917
  • commit date: 2023-02-10
  • overall geometric mean: 1.00x faster

Results vs. base

  • fork: Fidget_Spinner
  • ref: per_class_cache
  • machine: linux-x86_64
  • commit hash: 78c9301
  • commit date: 2023-01-09
  • overall geometric mean: 1.01x slower
Benchmark 2022-12-02_10-13-3.10-b027dd78bbdb 2022-12-01_13-07-3.11-9707bf228e00
deltablue 12.4 ms 6.44 ms: 1.92x faster
scimark_sor 329 ms 196 ms: 1.68x faster
logging_silent 279 ns 167 ns: 1.67x faster
logging_silent | 279 ns | 167 ns: 1.67x faster |
Benchmark 2022-09-13_08-28-main-49cceeb5c998 2022-10-23_09-32-for-iter-no-pop-d5dd9b40545f
unpack_sequence 81.0 ns 74.9 ns: 1.08x faster
scimark_sor 196 ms 187 ms: 1.05x faster
logging_silent 163 ns 157 ns: 1.04x faster
logging_silent | 163 ns | 157 ns: 1.04x faster |
Benchmark 2022-10-21_13-41-main-82ccbf69a842 2022-10-21_15-10-code-version-004b13250ff2
unpack_sequence 78.4 ns 73.5 ns: 1.07x faster
unpickle 23.0 us 21.6 us: 1.06x faster
scimark_lu 185 ms 179 ms: 1.03x faster
scimark_lu | 185 ms | 179 ms: 1.03x faster |