[erlang-questions] Erlang is the best choice for building commercial application servers

Jan Burse janburse@REDACTED
Wed Mar 14 11:06:08 CET 2012


Shahrdad Shadab schrieb:
> _Java performance is nowhere near Erlang.

Where is the evidence? I don't know
whether Joe would approve with this
statement?

Did a little micro benchmark: Erlang is
slower than Java. For general purpose
programming. Did not test some message
passing or so.

Here are some results for Naive Reverse:

Erlang 64-bit R15B: ~60 ms
Java 64-bit JDK 1.7: ~30 ms (Turbo boost ~15ms)

Tested on Windows 7,
Sony VAIO VPC-SA3J1E/XI,
CPU i5 2430M, 4GB RAM

------------------ benchmark.erl --------------------------

-module(benchmark).
-export([test/0,nrev/0]).

append([],X) -> X;
append([X|Y],Z) -> [X|append(Y,Z)].

reverse([]) -> [];
reverse([X|Y]) -> append(reverse(Y),[X]).

data() -> [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20, 
21,22,23,24,25,26,27,28,29,30].

nrev() -> reverse(data()).

for(0,F) -> true;
for(N,F) when N>0 -> apply(benchmark,F,[]), for(N-1,F).

bench(N,F) ->
{_,_,X}=os:timestamp(),
for(N,F),
{_,_,Y}=os:timestamp(),
io:write(F),
io:put_chars("\tin "),
io:write(Y-X),
io:put_chars(" (mics)"),
io:nl().

test() -> bench(6000,nrev).

---------------------- ConsCell.java ---------------------------

package demo.perpetual;

/**
  */
final class ConsCell {
     private final Object head;
     private final Object tail;

     ConsCell(Object h, Object t) {
         head = h;
         tail = t;
     }

     Object getHead() {
         return head;
     }

     Object getTail() {
         return tail;
     }

}

---------------------- NaiveReverse.java -----------------------------

package demo.perpetual;

/**
  */
public final class NaiveReverse {
     private static Object data;

     static {
         Object help = null;
         for (int i = 30; i >= 1; i--) {
             help = new ConsCell(Integer.valueOf(i), help);
         }
         data = help;
     }

     private static Object append(Object alfa, Object beta) {
         if (alfa == null) {
             return beta;
         } else {
             ConsCell help = (ConsCell) alfa;
             return new ConsCell(help.getHead(), append(help.getTail(), 
beta));
         }
     }

     private static Object reverse(Object alfa) {
         if (alfa == null) {
             return null;
         } else {
             ConsCell help = (ConsCell) alfa;
             return append(reverse(help.getTail()),
                     new ConsCell(help.getHead(), null));
         }
     }

     private static void _for(int n) {
         for (int i=0; i<n; i++) {
             reverse(data);
         }
     }

     private static void bench(int n) {
         long t1=System.nanoTime();
         _for(n);
         long t2=System.nanoTime();
         System.out.println("nrev\tin "+(t2-t1)+" (nanos)");
     }

     public static void main(String[] args) {
         bench(6000);
         bench(6000);
     }
}




More information about the erlang-questions mailing list