Path: csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Rod Pemberton" Newsgroups: comp.lang.forth Subject: Re: Stoked Date: Sat, 12 Dec 2015 11:25:12 -0500 Organization: Aioe.org NNTP Server Lines: 53 Message-ID: References: NNTP-Posting-Host: n4wpt9zq8xR26Ttf9mo2BA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.16 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.forth:44217 On Wed, 28 Oct 2015 18:41:08 -0400, Rod Pemberton wrote: > On Wed, 28 Oct 2015 12:18:07 -0400, Chris Curl wrote: >> It is not very fast though ... >> >> : test begin ?dup if 1 - else exit then again ; >> >> 10000000 test \ about 6 seconds for 10 million iterations >> > > As you noted, that's 100M. > > I get 7 seconds for my interpreted Forth for 100M. > That uses C's ctime() which reports with only one > second of accuracy. Just for reference, I converted the test code to C code via a conversion program I wrote, and all the high-level Forth words called by the routine too right down to my primitives. Then, I patched in my Forth primitives in C, C stack code, and other necessary C code to compile it. So, the test C code is effectively the same exact code which executes when the Forth is interpreted, but without the interpreter being present. The only difference is the test C code uses C's native control-flow instead of converting the control-flow words to C, i.e., BEGIN AGAIN IF ELSE THEN are not converted into equivalent code. I timed it. It's right on the boundary between 3 and 4 four seconds. So, the interpreter is twice as slow (7 seconds) as the code without the interpreter (3.5 seconds). Of course, there is a speed improvement due to the use of C's control-flow instead of needing to interpret the Forth control-flow words. I'm not sure if the overhead is mostly due to the interpreter, or if it's the control-flow, or if it's an even balance between them, but I suspect the interpreter itself. I suspect the equivalent code coded natively in C would likely be substantially faster. Rod Pemberton -- The idea sentient beings can be suppressed by a few simple rules is a farce. Even so, Isaac Asimov posited such rules for sentient artificial intelligence.