aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-09-16 18:26:49 +0200
committerMattias Andrée <maandree@kth.se>2021-09-16 18:26:49 +0200
commit63eeae2e150fc4dca0d178c2644db3d5c4a16328 (patch)
treefe453e9022dcaf41f4ea0ff665f2277a58bb01a2
parentadd alloca (diff)
downloadmalloc-vs-new-63eeae2e150fc4dca0d178c2644db3d5c4a16328.tar.gz
malloc-vs-new-63eeae2e150fc4dca0d178c2644db3d5c4a16328.tar.bz2
malloc-vs-new-63eeae2e150fc4dca0d178c2644db3d5c4a16328.tar.xz
Improve makefile, style, and gitignore
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--.gitignore6
-rw-r--r--COPYING1
-rw-r--r--Makefile24
-rw-r--r--README1
-rw-r--r--alloca.cc (renamed from src/alloca.cc)19
-rw-r--r--malloc.cc (renamed from src/malloc.cc)19
-rw-r--r--new.cc (renamed from src/new.cc)19
7 files changed, 47 insertions, 42 deletions
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/src/alloca.cc b/alloca.cc
index a46c69b..15dadcb 100644
--- a/src/alloca.cc
+++ b/alloca.cc
@@ -7,14 +7,15 @@
#include <cstdlib>
#include <alloca.h>
-int main(void)
+
+int
+main(void)
{
- char* a;
- size_t i;
-
- for (i = 0; i < 40000000UL; i++)
- a = (char*)alloca(16);
-
- return 0;
-}
+ char *a;
+ size_t i;
+ for (i = 0; i < 40000000UL; i++)
+ a = (char *)alloca(16);
+
+ return 0;
+}
diff --git a/src/malloc.cc b/malloc.cc
index 22b4cdb..18714c2 100644
--- a/src/malloc.cc
+++ b/malloc.cc
@@ -6,14 +6,15 @@
*/
#include <cstdlib>
-int main(void)
+
+int
+main(void)
{
- char* a;
- size_t i;
-
- for (i = 0; i < 40000000UL; i++)
- a = (char*)malloc(16);
-
- return 0;
-}
+ char *a;
+ size_t i;
+ for (i = 0; i < 40000000UL; i++)
+ a = (char *)malloc(16);
+
+ return 0;
+}
diff --git a/src/new.cc b/new.cc
index 5e96747..e463a2d 100644
--- a/src/new.cc
+++ b/new.cc
@@ -6,14 +6,15 @@
*/
#include <cstdlib>
-int main(void)
+
+int
+main(void)
{
- char* a;
- size_t i;
-
- for (i = 0; i < 40000000UL; i++)
- a = new char[16];
-
- return 0;
-}
+ char *a;
+ size_t i;
+ for (i = 0; i < 40000000UL; i++)
+ a = new char[16];
+
+ return 0;
+}