Re: [ooc-compiler] Language Shootout - a couple of problems
Brought to you by:
mva
|
From: Stewart G. <sgr...@ii...> - 2004-07-29 04:47:54
|
Hi Isaac, > Current OO2C implementations are shown at: > http://shootout.alioth.debian.org/lang/oberon2/ > > 1) Brent reports that for n=40000 Hash.ob2 gives 0 instead of 9999 > oo2c -M --no-rtc Hash.ob2 > However it works fine on my machine. Suggestions? > > 2) moments.oberon2 works fine for input size 1, but for input size 50 > Segmentation fault I couldn't try these, as they depend on some modules that are not listed. Are these files available via CVS or something? You shouldn't get a segmentation fault, unless it is due to an unchecked run-time error. Try running the program with run-time checking enabled. If it still segfaults, carefully check your use of unsafe functions from module SYSTEM. If you use gdb, you should be able to localise the error using the backtrace function. Looking at moments.oberon, I think the use of SYSTEM.MOVE is buggy. To copy an array of <N> REALs, you need to use <N*SIZE(REAL)> as the length parameter. You are probably getting a garbled array by not copying the whole thing. Also, I would avoid the use of ASH, since it is probably not faster than just multiplying by 2. Actually, it would be nice to have a type-safe way of quickly copying arrays (eg. like Java's System.arraycopy) > > 3) Suggestions on improving the performance of the file processing > programs (or any other programs) would be appreciated: wc.oberon2, > spellcheck.oberon2, sumcol.oberon2. It depends what these benchmarks are trying to measure. If they are trying to measure the speed of the underlying I/O facilities, they are probably fine. However, if you look at the examples that run fast, these all do buffering inside the application itself. For example, the gcc implementation does not use getchar(), but instead uses read() to read a chunk of data into a buffer, and then works on that array. You can do the same using the IO modules, and you should get similar performance. For example, try something like this: MODULE Wc2; IMPORT IO, IO:StdChannels, Out; VAR insideWord: BOOLEAN; nc, nl, nw: LONGINT; in : IO.ByteChannel; buffer : ARRAY 4096 OF CHAR; i, count : LONGINT; BEGIN nc := 0; nl := 0; nw := 0; insideWord := FALSE; in := StdChannels.stdin; REPEAT count := in.Read(buffer, 0, LEN(buffer) * SIZE(CHAR)); FOR i := 0 TO count-1 DO INC(nc); CASE buffer[i] OF | 0AX : INC(nl); insideWord := FALSE; | 9X, 20X : insideWord := FALSE; ELSE IF ~insideWord THEN insideWord := TRUE; INC(nw); END; END; END; UNTIL count <= 0; Out.Int(nl,1); Out.Char(20X); Out.Int(nw,0); Out.Char(20X); Out.Int(nc,0); Out.Ln; END Wc2. At least on my system, this version is about 10 times faster, even with run-time checks enabled. You should find that the same technique makes the other IO-based benchmarks run much faster too. Cheers, Stewart |