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


Groups > comp.lang.forth > #29593

Re: Forth vs Java in calculating partial sum ;)

Path csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!217.188.199.168.MISMATCH!takemy.news.telefonica.de!telefonica.de!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail
From Bernd Paysan <bernd.paysan@gmx.de>
Newsgroups comp.lang.forth
Subject Re: Forth vs Java in calculating partial sum ;)
Date Sat, 12 Apr 2014 22:50:50 +0200
Organization 1&1 Internet AG
Lines 53
Message-ID <lic8vb$dv4$1@online.de> (permalink)
References <libs3f$2r2$2@news.albasani.net> <ca9e51d1-059e-4116-8f7c-024b903395e2@googlegroups.com>
NNTP-Posting-Host p4ffb9415.dip0.t-ipconnect.de
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace online.de 1397335851 14308 79.251.148.21 (12 Apr 2014 20:50:51 GMT)
X-Complaints-To abuse@einsundeins.com
NNTP-Posting-Date Sat, 12 Apr 2014 20:50:51 +0000 (UTC)
User-Agent KNode/4.11.5
Xref csiph.com comp.lang.forth:29593

Show key headers only | View raw


mhx@iae.nl wrote:

> On Saturday, April 12, 2014 7:11:11 PM UTC+2, Melzzzzz wrote:
>> Seems that Java bits Forth in optimizing tight loops. Eg division by
>> constant optimization is performed automatically.
> 
> [..]
> 
> Paraphrased:
> 
> ANEW -cumul
> 
> #50000000 =: N
> N CELLS ALLOCATE ?ALLOCATE =: addr
> 
> : init_cumul ( -- ) addr  N 0 ?DO  I 3 / I +   SWAP !+   LOOP DROP ;
>           
> : cumul ( -- )
>         addr @+ ( [a] a -- )
>         N 1 ?DO
>                 OVER @ + DUP ( a [a]+x [a]+x -- )
>                 ROT !+ ( [a]+x a2 -- )        SWAP
>            LOOP 2DROP ;
> 
> : bench ( xt -- )
>         TIMER-RESET
>         EXECUTE
>         MS? S>F 1e-3 F* N S>F  F/  CR F.N1 ." s/op, "  .ELAPSED ;
> 
>   ' init_cumul bench
>   ' cumul      bench
> CR addr N 1- CELL[] @ .
>    addr FREE ?ALLOCATE
> 
> \ 3.68 ns/op, 0.186 seconds elapsed.
> \ 2.16 ns/op, 0.109 seconds elapsed.
> \ 1666666616666667  ok
> 
> I guess Java programmers are paid per LOC.

That's how I would write cumul (with the original stack effeckt, which 
Melzzzzz forgot to write):

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

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

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