Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #29669

Re: Forth vs Java in calculating partial sum ;)

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Forth vs Java in calculating partial sum ;)
Date 2014-04-15 14:44 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2014Apr15.164448@mips.complang.tuwien.ac.at> (permalink)
References <libs3f$2r2$2@news.albasani.net> <7x7g6upizf.fsf@ruckus.brouhaha.com> <lihfkl$g58$5@news.albasani.net> <534c6c9c.421218876@news.demon.co.uk> <lii4u9$p42$1@solani.org>

Show all headers | View raw


Melzzzzz <mel@zzzzz.invalid> writes:
>Including ../Lib/Ndp387.fth
>Including /home/bmaxa/examples/forth/cumul.fs
>238.09524=20
>555.55556=20
>262486571=20
>
>real	0m0.330s
>user	0m0.313s
>sys	0m0.016s
>
>
>It is much faster than gforth but still slower than Java.

Several things to note: 

1) The init takes longer than cumul, probably
mostly due to the division; if a compiler optimizes the division by
three, it will look significantly faster in this benchmark, but does
that transfer to other programs?

2) Note the significant proportion of system time, due to the need to
allocate 50MB of memory.

I tried this on a slower, simpler CPU (AMD E450), and compared the
three variants I posted earlier:

                  ticks it/tick
Melzzzzz cumul      440 113636.36 
  Paysan cumul      530 94339.623 
    Ertl cumul      400 125000. 

To check my theory that the large array size makes things mostly
memory-bound, I changed the benchmark to run repeatedly on a 2000-cell
array, same number of total iterations:

                  ticks it/tick
Melzzzzz cumul      410 121951.22 
  Paysan cumul      380 131578.95 
    Ertl cumul      450 111111.11 

Does not look like my memory-bound idea is actually true, and I don't
know how to explain the variations (especially why Paysan is slower
with a big array, but faster with a small one).

Let's look at a bigger CPU (Xeon 5450, like a Core 2 Quad):

With array size N=50M I get:

                  ticks it/tick
Melzzzzz cumul      170 294117.65 
  Paysan cumul      160 312500. 
    Ertl cumul      150 333333.33 

With array size N=2000 I get:

                  ticks it/tick
Melzzzzz cumul      140 357142.86 
  Paysan cumul      140 357142.86 
    Ertl cumul      150 333333.33 

Program below, invocation with

vfxlin "include /usr/share/doc/VfxForth/Lib/Ndp387.fth include cumul.fs bye"

- anton
---------------------
: iters 50000000 ;
: N 2000 ;

: init_cumul
	N 0 ?do
	i 3 / i +
	over i cells + !
	loop ;
	
: cumul 
    dup @ 
    N 1 ?do
        over i cells + @
        + 2dup
        swap i cells + !
    loop 
    drop ;

: bench ( addr xt -- addr )
    2dup (ticks) 0
    iters N / 0 ?do
        2over execute drop
    loop
    (ticks) 0
    2swap d- 2dup 8 d.r space d>f iters s>f fswap f/ f. cr 2drop drop ;

: cumul-paysan ( addr -- addr )
    dup N 1- cells bounds ?do
	i @ i cell+ +!
    cell +loop ;

: cumul-ertl ( addr -- addr )
  0 over N cells bounds ?do
    i @ + dup i !
  cell +loop 
  drop ;
    
N cells allocate throw
cr
\ ."           init " ' init_cumul bench
init_cumul
."                   ticks it/tick" cr
." Melzzzzz cumul " ' cumul bench
."   Paysan cumul " ' cumul-paysan bench
."     Ertl cumul " ' cumul-ertl bench
dup N 1 - cells + @ . cr
free throw

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Forth vs Java in calculating partial sum ;) Melzzzzz <mel@zzzzz.com> - 2014-04-12 19:11 +0200
  Re: Forth vs Java in calculating partial sum ;) Paul Rubin <no.email@nospam.invalid> - 2014-04-12 10:15 -0700
    Re: Forth vs Java in calculating partial sum ;) Melzzzzz <mel@zzzzz.com> - 2014-04-14 22:15 +0200
      Re: Forth vs Java in calculating partial sum ;) stephenXXX@mpeforth.com (Stephen Pelc) - 2014-04-14 23:20 +0000
        Re: Forth vs Java in calculating partial sum ;) Melzzzzz <mel@zzzzz.invalid> - 2014-04-15 04:18 +0200
          Re: Forth vs Java in calculating partial sum ;) m.a.m.hendrix@tue.nl - 2014-04-15 00:32 -0700
            Re: Forth vs Java in calculating partial sum ;) stephenXXX@mpeforth.com (Stephen Pelc) - 2014-04-15 11:33 +0000
            Re: Forth vs Java in calculating partial sum ;) Melzzzzz <mel@zzzzz.com> - 2014-04-15 15:55 +0200
          Re: Forth vs Java in calculating partial sum ;) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-04-15 14:44 +0000
            Re: Forth vs Java in calculating partial sum ;) Paul Rubin <no.email@nospam.invalid> - 2014-04-15 09:00 -0700
              Re: Forth vs Java in calculating partial sum ;) Melzzzzz <mel@zzzzz.invalid> - 2014-04-15 19:38 +0200
            Re: Forth vs Java in calculating partial sum ;) mhx@iae.nl - 2014-04-15 11:41 -0700
            Re: Forth vs Java in calculating partial sum ;) Melzzzzz <mel@zzzzz.com> - 2014-04-16 07:10 +0200
            Re: Forth vs Java in calculating partial sum ;) Melzzzzz <mel@zzzzz.com> - 2014-04-16 07:24 +0200
              Re: Forth vs Java in calculating partial sum ;) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-04-16 10:24 +0000
  Re: Forth vs Java in calculating partial sum ;) mhx@iae.nl - 2014-04-12 13:01 -0700
    Re: Forth vs Java in calculating partial sum ;) mhx@iae.nl - 2014-04-12 13:06 -0700
    Re: Forth vs Java in calculating partial sum ;) Paul Rubin <no.email@nospam.invalid> - 2014-04-12 15:49 -0700
      Re: Forth vs Java in calculating partial sum ;) mhx@iae.nl - 2014-04-12 23:00 -0700
        Re: Forth vs Java in calculating partial sum ;) Paul Rubin <no.email@nospam.invalid> - 2014-04-13 00:14 -0700
          Re: Forth vs Java in calculating partial sum ;) mhx@iae.nl - 2014-04-13 02:03 -0700
        Re: Forth vs Java in calculating partial sum ;) Bernd Paysan <bernd.paysan@gmx.de> - 2014-04-13 14:52 +0200
    Re: Forth vs Java in calculating partial sum ;) "WJ" <w_a_x_man@yahoo.com> - 2014-12-12 23:45 +0000
  Re: Forth vs Java in calculating partial sum ;) mhx@iae.nl - 2014-04-12 13:33 -0700
    Re: Forth vs Java in calculating partial sum ;) Bernd Paysan <bernd.paysan@gmx.de> - 2014-04-12 22:50 +0200
      Re: Forth vs Java in calculating partial sum ;) Melzzzzz <mel@zzzzz.invalid> - 2014-04-13 03:30 +0200
      Re: Forth vs Java in calculating partial sum ;) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-04-13 13:43 +0000
  Re: Forth vs Java in calculating partial sum ;) Andrew Haley <andrew29@littlepinkcloud.invalid> - 2014-04-15 10:05 -0500
  Re: Forth vs Java in calculating partial sum ;) "WJ" <w_a_x_man@yahoo.com> - 2014-12-05 05:46 +0000
  Re: Forth vs Java in calculating partial sum ;) "WJ" <w_a_x_man@yahoo.com> - 2014-12-10 09:50 +0000
    Re: Forth vs Java in calculating partial sum ;) "WJ" <w_a_x_man@yahoo.com> - 2014-12-10 18:29 +0000

csiph-web