Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #29610
| 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-13 13:43 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2014Apr13.154333@mips.complang.tuwien.ac.at> (permalink) |
| References | <libs3f$2r2$2@news.albasani.net> <ca9e51d1-059e-4116-8f7c-024b903395e2@googlegroups.com> <lic8vb$dv4$1@online.de> |
Bernd Paysan <bernd.paysan@gmx.de> writes:
>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 ;
Disadvantage: fetches every cell twice, and you have a recurrence
through memory, which may be quite expensive, maybe not on current
Intel processors, but on older Intel ones, and probably on many other
machines. So for performance I would write this as
: cumul ( addr -- addr )
0 over N 1- cells bounds ?do
i @ + dup i !
cell +loop
drop ;
(untested). And the loop body is even one char shorter:-).
Here are the loop bodies on VFX:
Melzzzzz Paysan Ertl
MOV EDX, [ESP] MOV EDX, [ESP] MOV EDX, [ESP]
SHL EDX, 02 MOV ECX, [ESP] ADD EBX, 0 [EDX]
ADD EDX, [EBP] MOV EAX, 0 [EDX] MOV EDX, [ESP]
ADD EBX, 0 [EDX] ADD [ECX+04], EAX MOV 0 [EDX], EBX
MOV EDX, [ESP] ADD [ESP], 04 ADD [ESP], 04
SHL EDX, 02 ADD [ESP+04], 04 ADD [ESP+04], 04
ADD EDX, [EBP] JNO 080BF3B0 JNO 080BF428
MOV 0 [EDX], EBX
ADD [ESP], 01
ADD [ESP+04], 01
JNO 080BF338
Allocating I (and the conditioned loop bound) into a register might
pay off for this kind of code.
As for the benchmark: Sure, when you do a tiny benchmark that uses int
instead of Integer, and uses arrays instead of something from the Java
Collection classes, like ArrayList, then the Java JIT can shine. And
to make sure of that, the original benchmark used a size (50*1000*1000
ints, i.e., 200MB) that far exceeds cache sizes, so any remaining
inefficiencies get swamped in the cache misses.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2013: http://www.euroforth.org/ef13/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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