From: Jeff Sturm <jsturm@on...> - 2001-05-24 18:45:36
> i test memory allocation and i had a big surprised.
> (i join a java, C#, C memory test) (yes i run on windows) and the C code
> was 2 times slower
> than java code ... (and 5 times slower than C# code, also)
A few points to make...
1) Memory allocation is one aspect of runtime performance. There are many
2) Your C example allocates 50 bytes at a time, whereas the Java example
contains just 3 ints and an object. With header info it is probably
closer to 20.
3) The Java example is too simplistic; the VM I tested optimizes `new
JNew()' away completely.
4) Your free() code in new.c is probably not very representative of how a
real GC works.
5) The malloc() in MSVCRT is likely to be lousy in performance.
I tried your example on a GNU/Linux desktop, modifying JNew.java to fool
the optimizer and adjusting SIZE in new.c to 20. Also I added a
modification of your new.c, linked against Boehm's conservative GC
[jsturm@... tmp]$ java JNew 1000000
Count to 1000000 in 401 ms.
[jsturm@... tmp]$ ./new 1000000
count to 1000000 in 0.26 s.
[jsturm@... tmp]$ ./gcnew 1000000
count to 1000000 in 0.18 s.
For a slightly better comparative test of GC performance in C, C++, Scheme
and Java, see
(A version of GCBench for C# would be interesting...)