Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #4628
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Subject | Re: Forth Performance Question |
| Newsgroups | comp.lang.forth |
| Message-ID | <14589696958436@frunobulax.edu> (permalink) |
| Date | 2011-08-07 07:45 +0200 |
| References | <f0fc528e-2fdb-42af-a66d-976ebfa73b88@c8g2000prn.googlegroups.com> |
| Organization | SunSITE.dk - Supporting Open source |
TS <thinksquared@gmail.com> wrote Re: Forth Performance Question
> Hi,
> I'm just starting to learn Forth, and trying to assess the performance
> differences between some of the common free Forths. I ran this
> program:
> : foo 1 1000000 * drop ;
> : test 1 100000000 ?DO foo LOOP ;
This "test: probably doesn't do what you think it does. It wouldn't
matter when used to compare 32-bit Forths, but it does when comparing
Forth to Java. What you probably intended is
: test 100000000 0 ?DO foo LOOP ;
> On BigForth 2.4.0 it took ~22 sec to run, Retro v11 (with "times"
> syntax, compiled with -O3), took ~23 sec and GForth 0.7.0 ~65 sec to
> run.
It is valid to compare the two Forths, given they are both either
32-bits or 64-bits.
[..]
> I'm using Ubuntu (64 bit).and GCC 4.4.3 on an Intel Core2 Duo laptop.
> I have two main questions:
> a) Since BigForth is compiles to native code, why is its performance
> similar to Retro, which is interpreted?
> public class Test {
> public static void main(String[] args) {
> for(int i = 0; i < 100000000; ++i){
> foo();
> }
> }
> private static final int foo(){
> return 1*1000000;
> }
> }
The compiler will not produce code for 1*1000000 (it's a constant),
and therefore the foo() function is inlined in main. Inlining
probably doesn't even happen because the efect of foo() can not
be observed outside the for loop. In that case the JIT may not even
compile the loop, and your only measuring the startup time of the
code. To do a true comparison you need multiply not 1 and 1000000,
but a and b, where a and b are integer arguments to main (so the JIT
can not predict what they are).
In Forth, the test word is not strictly interpreted. (It is better
to read up a bit on Forth before attempting to benchmark.)
A classical DO LOOP has very little overhead that can be optimized
away. And it is a stretch to call Retro "classical."
> b) Why the enormous difference in speed between Java (which is also
> based on a stack VM) and these Forths? Is it because the JIT performs
> inlining? Or might there be other reasons?
Here is Forth code which functionally matches your intention(?):
( Run on a 64-bit nc Forth, Windows 7 64bit, Intel Core i7 920, 2.67 GHz)
FORTH> : foo 1 1000000 * drop ;
FORTH> \ : test 1 100000000 ?DO foo LOOP ;
: test cr timer-reset 100000000 1 ?DO foo LOOP .elapsed ;
FORTH> test
0.219 seconds elapsed. ok
This puzzle does not exist.
-marcel
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Forth Performance Question TS <thinksquared@gmail.com> - 2011-08-06 20:43 -0700
Re: Forth Performance Question "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2011-08-07 01:02 -0400
Re: Forth Performance Question Chris Hinsley <chris.hinsley@gmail.com> - 2011-08-16 12:09 +0100
Re: Forth Performance Question stephenXXX@mpeforth.com (Stephen Pelc) - 2011-08-16 14:08 +0000
Re: Forth Performance Question mhx@iae.nl (Marcel Hendrix) - 2011-08-07 07:45 +0200
Re: Forth Performance Question anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-08-07 16:18 +0000
Re: Forth Performance Question Bruno Gauthier <bgauthier@free.fr> - 2011-08-07 07:53 +0200
Re: Forth Performance Question Julian Fondren <ayrnieu@gmail.com> - 2011-08-07 01:01 -0500
Re: Forth Performance Question Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-08-07 12:50 +0000
Re: Forth Performance Question stephenXXX@mpeforth.com (Stephen Pelc) - 2011-08-07 11:46 +0000
Re: Forth Performance Question Arnold Doray <thinksquared@gmail.com> - 2011-08-10 17:03 +0000
Re: Forth Performance Question Julian Fondren <ayrnieu@gmail.com> - 2011-08-10 13:35 -0500
Re: Forth Performance Question Arnold Doray <thinksquared@gmail.com> - 2011-08-11 15:05 +0000
Re: Forth Performance Question anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-08-11 16:26 +0000
Re: Forth Performance Question Arnold Doray <thinksquared@gmail.com> - 2011-08-12 08:15 +0000
Re: Forth Performance Question "Elizabeth D. Rather" <erather@forth.com> - 2011-08-11 22:29 -1000
Re: Forth Performance Question Arnold Doray <thinksquared@gmail.com> - 2011-08-12 10:09 +0000
Re: Forth Performance Question Julian Fondren <ayrnieu@gmail.com> - 2011-08-12 08:15 -0500
Re: Forth Performance Question anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-08-12 09:31 +0000
Re: Forth Performance Question crc <charles.childers@gmail.com> - 2011-08-11 10:27 -0700
Re: Forth Performance Question Julian Fondren <ayrnieu@gmail.com> - 2011-08-11 13:18 -0500
Re: Forth Performance Question "Elizabeth D. Rather" <erather@forth.com> - 2011-08-11 12:00 -1000
Re: Forth Performance Question Howerd <howerdo@yahoo.co.uk> - 2011-08-11 15:13 -0700
Re: Forth Performance Question Charles Childers <crc_nospam@retroforth.org> - 2011-08-11 20:52 -0400
Re: Forth Performance Question "Rod Pemberton" <do_not_have@noavailemail.cmm> - 2011-08-12 02:19 -0400
Re: Forth Performance Question Julian Fondren <ayrnieu@gmail.com> - 2011-08-12 02:10 -0500
Re: Forth Performance Question "Elizabeth D. Rather" <erather@forth.com> - 2011-08-11 21:48 -1000
Re: Forth Performance Question "Elizabeth D. Rather" <erather@forth.com> - 2011-08-11 21:41 -1000
Re: Forth Performance Question Charles Childers <crc_nospam@retroforth.org> - 2011-08-10 23:33 -0400
Re: Forth Performance Question Ron Aaron <rambamist@gmail.com> - 2011-08-11 08:59 +0300
Re: Forth Performance Question Arnold Doray <thinksquared@gmail.com> - 2011-08-11 13:48 +0000
Re: Forth Performance Question Charles Childers <crc@retroforth.org> - 2011-08-11 10:30 -0400
Re: Forth Performance Question Ron Aaron <rambamist@gmail.com> - 2011-08-11 08:46 +0300
Re: Forth Performance Question arc <arc@vorsicht-bissig.de> - 2011-08-12 12:20 +0000
Re: Forth Performance Question Arnold Doray <thinksquared@gmail.com> - 2011-08-12 13:59 +0000
Re: Forth Performance Question stephenXXX@mpeforth.com (Stephen Pelc) - 2011-08-12 15:11 +0000
Re: Forth Performance Question Arnold Doray <thinksquared@gmail.com> - 2011-08-12 17:49 +0000
Re: Forth Performance Question stephenXXX@mpeforth.com (Stephen Pelc) - 2011-08-12 19:38 +0000
Re: Forth Performance Question "Elizabeth D. Rather" <erather@forth.com> - 2011-08-12 12:41 -1000
Re: Forth Performance Question Arnold Doray <thinksquared@gmail.com> - 2011-08-13 03:35 +0000
Re: Forth Performance Question "Elizabeth D. Rather" <erather@forth.com> - 2011-08-12 17:52 -1000
Re: Forth Performance Question Paul Rubin <no.email@nospam.invalid> - 2011-08-12 23:55 -0700
Re: Forth Performance Question Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-08-14 09:01 +0000
Re: Forth Performance Question Paul Rubin <no.email@nospam.invalid> - 2011-08-14 01:36 -0700
Re: Forth Performance Question Arnold Doray <thinksquared@gmail.com> - 2011-08-15 01:43 +0000
Re: Forth Performance Question Hugh Aguilar <hughaguilar96@yahoo.com> - 2011-08-15 16:59 -0700
Re: Forth Performance Question Mark Wills <markrobertwills@yahoo.co.uk> - 2011-08-16 03:25 -0700
Re: Forth Performance Question Arnold Doray <thinksquared@gmail.com> - 2011-08-16 11:22 +0000
Re: Forth Performance Question Hugh Aguilar <hughaguilar96@yahoo.com> - 2011-08-16 14:37 -0700
Re: Forth Performance Question Arnold Doray <thinksquared@gmail.com> - 2011-08-19 14:11 +0000
Re: Forth Performance Question Hugh Aguilar <hughaguilar96@yahoo.com> - 2011-08-22 19:52 -0700
Re: Forth Performance Question Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2011-08-13 02:28 +0200
Re: Forth Performance Question Zbiggy <zbigniew2011REMOVE@gmail.REMOVE.com> - 2011-08-12 20:53 +0200
csiph-web