4 ms·
But forth is a very low level language isn’t it? Even though it’s interpreter, it’s naturally going to be a lot faster than JS and even Java because it maps ver
by sbjs 8y ago
But forth is a very low level language isn’t it? Even though it’s interpreter, it’s naturally going to be a lot faster than JS and even Java because it maps very closely to the assembler instructions you would normally write by hand. So it would be probably 3x slower than C assuming every Forth instruction takes three C instructions to run (get opcode and arguments, do operation, push on stack).
- rpiguy 8y agoI have no idea how FORTH stacks up (haha) to other languages on modern machines insofar as speed is concerned. Modern FORTH is compiled so the difference may be quite less than the 3x you are proposing. On older machines, you will find published benchmarks showing FORTH to be 10 times slower than assembly. Compare this to BASIC which was usually 30-40 times slower than assembly in the best bases. I think your 3x speed difference between C and FORTH to be on the ball for these earlier machines. The other advantage of FORTH on these old microcomputers/microcontrollers is that threaded code tends to be quite compact, so you can write larger programs. Efficient use of memory was tantamount on old machines and controllers.
- ehaliewicz2 8y agoIt greatly depends on your forth compiler. Most hobby forth compilers are simple, and just lay down addresses to words or native call instructions, sometimes with inlining. These aren't slow, but they won't get close to C optimized by modern compilers. Production Forths like SwiftForth apparently have optimizing compilers, but I've never used them.
- rwmj 8y agoI wrote jonesforth which is a simple threaded FORTH (in other words, interpreted and certainly not a modern FORTH). Threaded interpreters produce compact code. They are not efficient on modern CPUs, because they interact badly with branch prediction. For embedded cases where memory is at a premium and you usually have a simple CPU like an Arduino, FORTH is a great fit still. Modern FORTHs are all compiled (as indeed are modern Javascripts). In my view FORTH is a pretty horrible language to write code in, and if you lose the advantage of the compact code for the embedded case then you might as well use a nice compiled language - whatever is your preference, but my preference would not be FORTH if I had to write code all day long in it.
- sbjs 8y agoI wonder if the same semantics that make Forth simple and fast can be used with another (higher-level) syntax to make it easier to write in, kind of like how C replaced Assembly. It could become a new family of languages that might rival modern high-level languages in the same way CL Lisp tried to shake things up by being both low-level and high-level at the same time.
- vanderZwan 8y agoYou might be interested in looking up concatenative languages. There's a wiki[0]. I really like Joy in the abstract sense. Factor made a few waves a decade ago but has kind of lost steam[1]. It's still being developed though[2]. Kitten looks promising but develops at a snail pace because it's one guy doing it[3]. Not a dig against him, mind you! [0] http://concatenative.org/wiki/view/Front%20Page http://concatenative.org/wiki/view/Front%20Page [1] http://factorcode.org/ http://factorcode.org/ [2] https://github.com/factor/factor/ https://github.com/factor/factor/ [3] http://kittenlang.org/ http://kittenlang.org/
- AstroJetson 8y agoJonesforth is a great tool when trying to teach people how stack based interpreters would work. I used it as an example in a class that I taught. The documentation is first rate with exact descriptions in the code. As far as the FORTH being a horrible language, to some extent it is. But if you are stuffing into a small chipset it's good. Granted there are things like Lua now, but back in the early years, FORTH was a huge tool for imbedded systems.
- eadmund 8y agoI look at Forth as a great portable assembler in which to write another expressive language (e.g. a Lisp or Smalltalk) in.