Skip to content

Commit c8663d5

Browse files
committed
so/testing: benchmark
1 parent e1f1552 commit c8663d5

2 files changed

Lines changed: 511 additions & 0 deletions

File tree

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ GCC_DOCKER = docker run --rm -v "$(shell pwd)":/src -w /src gcc:15.2.0
88
compiler ?= $(СС)
99
RUN_CMD = ./build/main
1010

11+
# Set CC and CFLAGS based on the selected compiler.
1112
ifeq ($(compiler), clang)
1213
CC = $(CLANG)
1314
else ifeq ($(compiler), gcc)
@@ -19,6 +20,20 @@ else ifeq ($(compiler), docker)
1920
RUN_CMD = $(GCC_DOCKER) ./build/main
2021
endif
2122

23+
# Preload mimalloc if available.
24+
UNAME_S := $(shell uname -s)
25+
ifeq ($(UNAME_S),Darwin)
26+
MIMALLOC_LIB := $(shell ls /opt/homebrew/lib/libmimalloc.dylib /usr/local/lib/libmimalloc.dylib 2>/dev/null | head -1)
27+
ifneq ($(MIMALLOC_LIB),)
28+
MIMALLOC_PRELOAD := DYLD_INSERT_LIBRARIES=$(MIMALLOC_LIB)
29+
endif
30+
else ifeq ($(UNAME_S),Linux)
31+
MIMALLOC_LIB := $(shell ls /usr/lib/libmimalloc.so /usr/local/lib/libmimalloc.so 2>/dev/null | head -1)
32+
ifneq ($(MIMALLOC_LIB),)
33+
MIMALLOC_PRELOAD := LD_PRELOAD=$(MIMALLOC_LIB)
34+
endif
35+
endif
36+
2237
inspect:
2338
go run ./cmd/inspect -- $(path)
2439

@@ -78,3 +93,10 @@ run-c:
7893
@$(CC) -O1 $(CFLAGS) -I$(path) -o build/main $(shell find $(path) -name "*.c") $(LDLIBS)
7994
@$(RUN_CMD)
8095
@rm -f build/main
96+
97+
.PHONY: bench
98+
bench:
99+
@cd bench/$(name) && go test -bench=.
100+
@CFLAGS="-Ofast -march=native -flto -funroll-loops" \
101+
$(MIMALLOC_PRELOAD) \
102+
go run ./cmd/so run ./bench/$(name)

0 commit comments

Comments
 (0)