From 63eeae2e150fc4dca0d178c2644db3d5c4a16328 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 16 Sep 2021 18:26:49 +0200 Subject: Improve makefile, style, and gitignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- .gitignore | 6 ------ COPYING | 1 - Makefile | 24 +++++++++++++++++------- README | 1 - alloca.cc | 21 +++++++++++++++++++++ malloc.cc | 20 ++++++++++++++++++++ new.cc | 20 ++++++++++++++++++++ src/alloca.cc | 20 -------------------- src/malloc.cc | 19 ------------------- src/new.cc | 19 ------------------- 10 files changed, 78 insertions(+), 73 deletions(-) create mode 100644 alloca.cc create mode 100644 malloc.cc create mode 100644 new.cc delete mode 100644 src/alloca.cc delete mode 100644 src/malloc.cc delete mode 100644 src/new.cc diff --git a/.gitignore b/.gitignore index e58d800..80d472a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,4 @@ -_/ -bin/ -obj/ \#*\# -.* -!.git* *~ *.bak *.swo @@ -13,4 +8,3 @@ obj/ *.su *.gch *.s - diff --git a/COPYING b/COPYING index 7fd7747..662cfe1 100644 --- a/COPYING +++ b/COPYING @@ -2,4 +2,3 @@ Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty. - diff --git a/Makefile b/Makefile index da0a418..6b411d7 100644 --- a/Makefile +++ b/Makefile @@ -2,17 +2,27 @@ # are permitted in any medium without royalty provided the copyright # notice and this notice are preserved. This file is offered as-is, # without any warranty. +.POSIX: +CXX = c++ -.PHONY: all -all: bin/malloc bin/new bin/alloca +BIN = malloc new alloca +OBJ = $(BIN:=.o) -bin/%: src/%.cc - @mkdir -p bin - $(CXX) -O0 -o $@ $^ +all: $(BIN) +$(OBJ): + +.cc.o: + $(CXX) -c -o $@ $< -O0 + +.o: + $(CXX) -o $@ $< -.PHONY: clean clean: - -rm -r bin + -rm -f -- *.o $(BIN) + +.SUFFIXES: +.SUFFIXES: .o .cc +.PHONY: all clean diff --git a/README b/README index e2adb86..313b165 100644 --- a/README +++ b/README @@ -1,2 +1 @@ `malloc` is faster than `new` in C++. - diff --git a/alloca.cc b/alloca.cc new file mode 100644 index 0000000..15dadcb --- /dev/null +++ b/alloca.cc @@ -0,0 +1,21 @@ +/** + * Copying and distribution of this file, with or without modification, + * are permitted in any medium without royalty provided the copyright + * notice and this notice are preserved. This file is offered as-is, + * without any warranty. + */ +#include +#include + + +int +main(void) +{ + char *a; + size_t i; + + for (i = 0; i < 40000000UL; i++) + a = (char *)alloca(16); + + return 0; +} diff --git a/malloc.cc b/malloc.cc new file mode 100644 index 0000000..18714c2 --- /dev/null +++ b/malloc.cc @@ -0,0 +1,20 @@ +/** + * Copying and distribution of this file, with or without modification, + * are permitted in any medium without royalty provided the copyright + * notice and this notice are preserved. This file is offered as-is, + * without any warranty. + */ +#include + + +int +main(void) +{ + char *a; + size_t i; + + for (i = 0; i < 40000000UL; i++) + a = (char *)malloc(16); + + return 0; +} diff --git a/new.cc b/new.cc new file mode 100644 index 0000000..e463a2d --- /dev/null +++ b/new.cc @@ -0,0 +1,20 @@ +/** + * Copying and distribution of this file, with or without modification, + * are permitted in any medium without royalty provided the copyright + * notice and this notice are preserved. This file is offered as-is, + * without any warranty. + */ +#include + + +int +main(void) +{ + char *a; + size_t i; + + for (i = 0; i < 40000000UL; i++) + a = new char[16]; + + return 0; +} diff --git a/src/alloca.cc b/src/alloca.cc deleted file mode 100644 index a46c69b..0000000 --- a/src/alloca.cc +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. This file is offered as-is, - * without any warranty. - */ -#include -#include - -int main(void) -{ - char* a; - size_t i; - - for (i = 0; i < 40000000UL; i++) - a = (char*)alloca(16); - - return 0; -} - diff --git a/src/malloc.cc b/src/malloc.cc deleted file mode 100644 index 22b4cdb..0000000 --- a/src/malloc.cc +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. This file is offered as-is, - * without any warranty. - */ -#include - -int main(void) -{ - char* a; - size_t i; - - for (i = 0; i < 40000000UL; i++) - a = (char*)malloc(16); - - return 0; -} - diff --git a/src/new.cc b/src/new.cc deleted file mode 100644 index 5e96747..0000000 --- a/src/new.cc +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copying and distribution of this file, with or without modification, - * are permitted in any medium without royalty provided the copyright - * notice and this notice are preserved. This file is offered as-is, - * without any warranty. - */ -#include - -int main(void) -{ - char* a; - size_t i; - - for (i = 0; i < 40000000UL; i++) - a = new char[16]; - - return 0; -} - -- cgit v1.2.3-70-g09d2