Been playing

2006-07-01 23:20:17 PST

Tags: , , ,

So I found this (bcompile) on reddit. It's a tutorial on bootstrapping/writting a compiler starting only with a hex to binary compiler.

So I was thinking about languages again. And it's the summer (maybe that time of year again?). So today on this holiday weekend I bashed out a language that was as fast as I could make it (rather crappy as a side effect ;)).

ftp://ftp.mindstab.net/lang-2006.07.01.tar.gz

README

Unnamed language.
<haplo @mindstab.net>
www.mindstab.net

I wrote this 'language' in a day.  It's only goal was to be as fast as I
could make it.  To that end it has little to no error correction, and
statically sized buffers.  Still, it's pretty fast.

Compared to vm-proto, the 'language' I wrote last year:

vm-proto:
        assembly like syntax
        compiles to endian safe object code
        ~2.5x slower at calculating primes than unnamed lang
        has some registers
        written in c++
        usage:
                compile foo.vms
                vm foo.vmo

Unnamed lang:
        assembly like syntax
        compiles and executes code in memory
        (possibly endian safe but untested)
        about  1/3 code size of vm-proto
        has some registers
        has a working stack (small, but can be enlarged in the code by a define)
        written in dirty c (function and variable names aren't the sanest)
        usage:
                lang < foo.src

Considering this is about as fast as I can think to make a language, I honestly
don't know how languages that are so much more fully featured like PHP are
written considering PHP is only marginally slower (and faster than vm-proto),
and I assume VM's like mono and java compile their byte code to architecture
machine code at some point. (?)

I also have been running some bench marks with my old primes suite.

1000000

(1/36) C results:
Compile [gcc]:          0.10 seconds
Execute:                0.88 seconds

(4/36) x86 Assembly results:
Compile [gcc]:          0.04 seconds
Execute:                0.76 seconds

(13/36) C# (Mono) results:
Compile [mcs]:          1.03 seconds
Execute [mono]:         1.74 seconds

(16/36) AWK results:
Execute [awk]:          23.6 seconds

(17/36) PERL results:
Execute [perl]:         22.4 seconds

(18/36) PHP results:
Execute [php]:          9.65 seconds

(19/36) Python results:
Execute [python]:       41.3 seconds

(21/36) Ruby results:
Execute [ruby]:         227. seconds

(22/36) Common Lisp results:
Execute [sbcl]:         10.5 seconds

Compile [gcl]:          0.00 seconds
Execute [gcl]:          23.7 seconds

(26/36) Fourth results:
Execute [gforth-fast]:  2.15 seconds

haplo@nika ~/src/my/lang/vm-proto $ time ./vm primes.vmo > /dev/null
real    0m25.325s
user    0m25.226s
sys     0m0.052s

haplo@nika ~/src/my/lang/fast-lang $ time ./lang < primes.src >/dev/null
real    0m7.558s
user    0m7.412s
sys     0m0.024s

[Update: 2006.07.02]
optimized lang
haplo@nika ~/src/my/lang/fast-lang $ time ./lang < primes.src  > /dev/null
real    0m3.753s
user    0m3.736s
sys     0m0.008s

As you can see, PHP5 is really fast for it's class (interpreted language). I was surprised. Ruby is distressingly slow. Mono is rather closer to native compiled speed. And my newest language beats all the fancy interpreted languages! (I'm pretty sure forth has a pretty clear machine code compile path :)).

[Update: I was surprised to find out that GCL is slower by far than SBCL even though GCL compiles Lisp.]

[last published version of primes can still be found at ftp://ftp.mindstab.net/primes with both a .tar.gz available for download and all the source online for browsing.]

Leave a Reply

Valid XHTML 1.0!
Valid CSS!
Mindstab.net is proudly powered by WordPress
Entries (RSS) and Comments (RSS).
20 queries. 0.414 seconds.