commit 00c7f8cdf97fa886669c4a8b7be3236dc340ed36
parent d744bcd354811876058f9a3b69fedbb3ba54df10
Author: NunoSempere <nuno.sempere@protonmail.com>
Date: Sat, 15 Jul 2023 23:26:48 +0200
add scratchpad
Diffstat:
3 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/scratchpad/makefile b/scratchpad/makefile
@@ -0,0 +1,57 @@
+# Interface:
+# make
+# make build
+# make format
+# make run
+
+# Compiler
+CC=gcc # required for nested functions
+# CC=tcc # <= faster compilation
+
+# Main file
+SRC=scratchpad.c
+OUTPUT=scratchpad
+
+## Dependencies
+MATH=-lm
+DEPENDENCIES=$(MATH)
+# OPENMP=-fopenmp
+
+## Flags
+DEBUG= #'-g'
+STANDARD=-std=gnu99 ## allows for nested functions.
+EXTENSIONS= #-fnested-functions
+WARNINGS=-Wall
+OPTIMIZED=-O3#-Ofast
+CFLAGS=$(DEBUG) $(STANDARD) $(EXTENSIONS) $(WARNINGS) $(OPTIMIZED)
+
+## Formatter
+STYLE_BLUEPRINT=webkit
+FORMATTER=clang-format -i -style=$(STYLE_BLUEPRINT)
+
+## make build
+build: $(SRC)
+ # gcc -std=gnu99 scratchpad.c -lm -o scratchpad
+ $(CC) $(CFLAGS) $(SRC) $(DEPENDENCIES) -o $(OUTPUT)
+
+format: $(SRC)
+ $(FORMATTER) $(SRC)
+
+run: $(SRC) $(OUTPUT)
+ ./$(OUTPUT) && echo
+
+time-linux:
+ @echo "Requires /bin/time, found on GNU/Linux systems" && echo
+
+ @echo "Running 100x and taking avg time $(OUTPUT)"
+ @t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {1..100}; do $(OUTPUT); done' 2>&1 >/dev/null | grep real | awk '{print $$2}' ); echo "scale=2; 1000 * $$t / 100" | bc | sed "s|^|Time using 1 thread: |" | sed 's|$$|ms|' && echo
+
+## Profiling
+
+profile-linux:
+ echo "Requires perf, which depends on the kernel version, and might be in linux-tools package or similar"
+ echo "Must be run as sudo"
+ $(CC) $(SRC) $(MATH) -o $(OUTPUT)
+ sudo perf record $(OUTPUT)
+ sudo perf report
+ rm perf.data
diff --git a/scratchpad/scratchpad b/scratchpad/scratchpad
Binary files differ.
diff --git a/scratchpad/scratchpad.c b/scratchpad/scratchpad.c
@@ -0,0 +1,7 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(){
+ printf("Hello world");
+}