jahboater
Posts: 4462
Joined: Wed Feb 04, 2015 6:38 pm

Re: Why Avoid BASIC on RPi?

Thu Apr 18, 2019 9:49 am

hippy wrote:
Thu Apr 18, 2019 9:10 am
I am not sure how any expression evaluating code would be anything but overly long. I would argue for string and multi-argument functions - Int(Left$(Date$,4)) and the like - to prove it is a capable evaluation engine.
I think simple arithmetic expressions were the suggestion, otherwise you are right it would definately be too large.
Hmm... how about a new challenge: Create an expression parser and evaluate the expression in the language of your choice? Could be simple maths expressions like "x := (x + y) * (1 - sin(2 * π * t))". Assume x,y etc have values. Would have to have a somewhat weird syntax to stop people just using "eval" in their language.
I would stick with one data type only, probably just floats. Adding integers more than doubles the size of the execute function because integer overflow detection is fiddly to say the least, whereas floating point error handling is trivial.
Adding unsigned integers is just another complication that doesn't show any more about the parser's ability.

The program could read lines of text from a file and/or from the terminal, parse and execute them, quit on EOF.
A sample test file could be given here.

At the end of the day, people who have programmed it will have a usable calculator, which is quite satisfying.

hippy
Posts: 5367
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Why Avoid BASIC on RPi?

Thu Apr 18, 2019 10:25 am

jahboater wrote:
Thu Apr 18, 2019 9:49 am
At the end of the day, people who have programmed it will have a usable calculator, which is quite satisfying.
Probably. But I don't see the relevance to the thread the OP started. It would make sense if all these suggestions related to doing it in Basic, to prove its worth, but it seems to be more a case of 'anything but Basic'.

jahboater
Posts: 4462
Joined: Wed Feb 04, 2015 6:38 pm

Re: Why Avoid BASIC on RPi?

Thu Apr 18, 2019 10:54 am

hippy wrote:
Thu Apr 18, 2019 10:25 am
jahboater wrote:
Thu Apr 18, 2019 9:49 am
At the end of the day, people who have programmed it will have a usable calculator, which is quite satisfying.
Probably. But I don't see the relevance to the thread the OP started. It would make sense if all these suggestions related to doing it in Basic, to prove its worth, but it seems to be more a case of 'anything but Basic'.
I think the original post was based on the false premise that the RPF were actively avoiding BASIC, which they are not.

About BASIC,
It has occurred to me that in the early days Fortran was just as lacking in structure as BASIC was, with a heavy reliance on numeric labels and gotos. Yet Fortran was always considered a serious "proper" language used by scientists and professionals - unlike BASIC.
Perhaps because of the name, perhaps because Fortran was compiled not interpreted, perhaps because Fortran was only available on larger expensive computers, I don't know.

Heater
Posts: 12699
Joined: Tue Jul 17, 2012 3:02 pm

Re: Why Avoid BASIC on RPi?

Thu Apr 18, 2019 11:42 am

hippy,

Yeah, it's all a bit of a mess here.

I won't be promoting any parser, game or any other challenge soon. Don't have the will or the time for it.

As for the intent here...

The original opening question was "Why avoid BASIC...". If one is going to advise avoiding BASIC it's probably good idea to suggest alternatives. Which is what has happened here. With demo programs.

Anyway, I learned a thing or two whilst tinkering with various alternatives here.

I have almost no experience of FORTRAN. It was one of the first high level languages, the performance of the compiled code was clearly attractive.

User avatar
PeterO
Posts: 4732
Joined: Sun Jul 22, 2012 4:14 pm

Re: Why Avoid BASIC on RPi?

Thu Apr 18, 2019 11:53 am

Does it really matter what happened 70 pages ago ?
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

jahboater
Posts: 4462
Joined: Wed Feb 04, 2015 6:38 pm

Re: Why Avoid BASIC on RPi?

Thu Apr 18, 2019 12:00 pm

Heater wrote:
Thu Apr 18, 2019 11:42 am
I have almost no experience of FORTRAN. It was one of the first high level languages, the performance of the compiled code was clearly attractive.
Here is an example of a well known error at NASA :-

do 10 i = 1,5
...
10

loops 5 times

do 10 i = 1.5
...
10

declares a new variable "do10i" (floating point because it starts with D) initialised to 1.5
The loop is executed once only.
A single character typo, no warnings nothing!

hippy
Posts: 5367
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Why Avoid BASIC on RPi?

Thu Apr 18, 2019 2:54 pm

PeterO wrote:
Thu Apr 18, 2019 11:53 am
Does it really matter what happened 70 pages ago ?
PeterO
I guess not. I was just trying to figure out what the point of this thread now is. It seems to me to have just descended somewhat into random ramblings. I was tempted to post a non-Basic example for expression evaluation, as asked for, but found myself asking whether I should, whether it actually serves any purpose.

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Why Avoid BASIC on RPi?

Thu Apr 18, 2019 2:59 pm

About BASIC, 
It has occurred to me that in the early days Fortran was just as lacking in structure as BASIC was, with a heavy reliance on numeric labels and gotos. Yet Fortran was always considered a serious "proper" language used by scientists and professionals - unlike BASIC.
Perhaps because of the name, perhaps because Fortran was compiled not interpreted, perhaps because Fortran was only available on larger expensive computers, I don't know.
Business BASIC (Basic IV, REXON, BBx, ...) was the beginning of BASIC as a business language. MS picked up on the idea and created QuickBASIC.

Heater
Posts: 12699
Joined: Tue Jul 17, 2012 3:02 pm

Re: Why Avoid BASIC on RPi?

Thu Apr 18, 2019 3:05 pm

Hippy,

I think....

You are right, this thread has gotten far too long and diverged from the original question. Which was answered in the first few pages.

I should have broken out a new thread for the fibo(4784969) challenge ages ago. It's a bit late for that now. My bad. Of course you could say that challenge is useless as well. Too which I'd say, it was interesting and fun for the participants, we learned a few things along the way.

If anyone wants to issue a new coding challenge it might be wise to start a new thread for it. Perhaps in the general programming section of the forum.

Heater
Posts: 12699
Joined: Tue Jul 17, 2012 3:02 pm

Re: Why Avoid BASIC on RPi?

Thu Apr 18, 2019 3:31 pm

Tim,

Not having much luck running your bigFib.sc on Windows 10 here:
In order to ease the pain you obviously suffer from with those nasty windows, try this simple commandline incantation, which requires that you actually have
a) a squeak VM that will be found in your path or whatever mechanism is used
Check.

>Squeak Squeak5.2-18229-64bit.image

actually runs. Yesterday it was complaining on start up that some .chages file was not writable. Today it does not. I have not changed any permissions. Go figure.
b) a squeak image file which will probably be names something like 'Squeak5.2b-18255-32bit.image'
Check.
See above.
c) the atttached bigFib.cs Smalltalk chunk file
Check.
I extracted bigFib.cs to the directory containing the Squeak stuff.
Then, with any filename substitutions required, run
squeak Squeak5.2b-18255-32bit.image bigFib.cs
It will start up, open the window, load the big fibonacci code and run 4784969 fastDoublingFib and print the time taken to stdout.
FAIL.

I run it as follows:

...\Squeak5.2-18229-64bit-201810190412-Windows>Squeak.exe Squeak5.2-18229-64bit.image bigFib.cs

Squeak opens up and displays a "ReadingAReadStream" progress bar. Usefully not telling us what it is reading.

Progress hangs toward the end and an error dialog pops up saying "Error: stdout is unavailable".

WTF?

Any help appreciated.

ejolson
Posts: 3073
Joined: Tue Mar 18, 2014 11:47 am

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 12:36 am

I looked for Yet Another Fibonacci Language and found GNU bc the Basic Calculator. The code is

Code: Select all

#!/usr/bin/bc -q
define fibo(n){
    if(n==0){
        a=0; b=1;
        return a;
    }
    y=fibo(n/2);
    if(n%2==0){
        t1=2*b-a; a*=t1; b*=t1;
        if(n%4==0) b-=1 else b+=1;
    } else {
        t1=2*a+b; a*=t1; b*=t1;
        if(n%4==1) a+=1 else a-=1;
    }
    return a;
}
fibo(4784969);
quit;
and the output

Code: Select all

$ time ./bcfibo | tail -c32
4856539211500699706378405156269

real    0m31.296s
user    0m31.271s
sys 0m0.029s
running on a Ryzen 7.
Last edited by ejolson on Fri Apr 19, 2019 4:55 pm, edited 1 time in total.

Heater
Posts: 12699
Joined: Tue Jul 17, 2012 3:02 pm

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 2:07 am

What is a Ryzen 7?

Is that one of those new fangled AMDs at 300 dollars a pop?

On my ancient i7 2600K salvaged from office throw outs it takes 36 seconds:

Code: Select all

$ time ./fibo.bc | tail -c32
4856539211500699706378405156269

real    0m36.363s
user    0m36.156s
sys     0m0.203s

User avatar
Paeryn
Posts: 2567
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 3:51 am

I think the humble RPi3 does fairly well then considering those times :-

Code: Select all

[email protected]:~ $ time ./fib.sh |tail -c32
4856539211500699706378405156269

real    2m27.222s
user    2m27.130s
sys     0m0.050s
She who travels light — forgot something.

ejolson
Posts: 3073
Joined: Tue Mar 18, 2014 11:47 am

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 4:25 am

Heater wrote:
Fri Apr 19, 2019 2:07 am
What is is a Ryzen 7?

Is that one of those new fangled AMDs at 300 dollars a pop?

On my ancient i7 2600K salvaged from office throw outs it takes 36 seconds:

Code: Select all

$ time ./fibo.bc | tail -c32
4856539211500699706378405156269

real    0m36.363s
user    0m36.156s
sys     0m0.203s
The Ryzen 7 is an 8-core x86-compatible AMD desktop processor listed around US $200 running in a new but inexpensive office computer. Single-core performance seems not much better than your older i7, though I suspect even a newer i5 would run faster than either. It's interesting that the Pi is not that much slower.

When the Fibonacci code for the Basic Calculator is so simple, why avoid Basic?

jahboater
Posts: 4462
Joined: Wed Feb 04, 2015 6:38 pm

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 4:42 am

Pi3B+

Code: Select all

$ time ./fibo.bc | tail -c32
4856539211500699706378405156269

real	2m6.161s
user	2m6.106s
sys	0m0.186s
Pi Zero

Code: Select all

$ time ./fibo.bc | tail -c32
4856539211500699706378405156269

real	4m31.928s
user	4m31.045s
sys	0m0.611s
Intel Core i7-3770K

Code: Select all

$ time ./fibo.bc | tail -c32
4856539211500699706378405156269

real	0m30.242s
user	0m30.232s
sys	0m0.024s

User avatar
rpdom
Posts: 14472
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 5:42 am

ejolson wrote:
Fri Apr 19, 2019 4:25 am
The Ryzen 7 is an 8-core x86-compatible AMD desktop processor listed around US $200 running in a new but inexpensive office computer. Single-core performance seems not much better than your older i7, though I suspect even a newer i5 would run faster than either.
i5 8265U (laptop):

Code: Select all

$ time ./bcfibo  | tail -c32
4856539211500699706378405156269

real	0m30.048s
user	0m30.052s
sys	0m0.013s

Heater
Posts: 12699
Joined: Tue Jul 17, 2012 3:02 pm

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 6:27 am

Yeah, I know what is a Ryzen it's just that there seems to be a huge variety of them.

If I picked one up locally it would be more like 300 dollars. Of course then I'd need a mother board etc.

This is amazing. This i7 is almost 10 years old. Today's Ryzen is only about 7% faster in single core performance. Moore's Law really has been dead since they started saying it was. (Yeah, I know Moore was talking about the economic sweet spot of the number of transistors on a chip not their speed but still.)

The Pi are doing very well at 1/4 the speed. Extremely well if you take into account price, 8 complete computers for the price of a CPU chip, size, and power consumption.

Whilst an upgrade to a new Ryzen PC/laptop makes no economic sense on a performance basis it looks like I could do with an upgrade to Pi3B+. I only get this using the 64 bit pi64 OS:

Code: Select all

$ time bc fibo.bc | tail -c32
4856539211500699706378405156269

real    2m43.042s
user    2m42.911s
sys     0m0.259s

jahboater
Posts: 4462
Joined: Wed Feb 04, 2015 6:38 pm

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 7:23 am

Heater wrote:
Fri Apr 19, 2019 6:27 am
This is amazing. This i7 is almost 10 years old. Today's Ryzen is only about 7% faster in single core performance. Moore's Law really has been dead since they started saying it was.
That comparison is possibly apples vs oranges.
Try a coffee-lake chip to see moores law still working ...
https://www.intel.com/content/www/us/en ... 9900k.html

Odroid-C2 (Cortex-A53 in 64-bit mode 1.7GHz)

Code: Select all

$ time bc ./fibo.bc | tail -c32
4856539211500699706378405156269

real	1m45.391s
user	1m45.190s
sys	0m0.180s

Heater
Posts: 12699
Joined: Tue Jul 17, 2012 3:02 pm

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 8:03 am

jahboater,
Try a coffee-lake chip to see moores law still working ...
https://www.intel.com/content/www/us/en ... 9900k.html
On the contrary, it looks like that coffee-lake demonstrates that Moore's Law, as people normally think of it, is dead.

Moore's Law is said to predict a doubling of transistors/performance every two years or so. On that basis I should be looking forward to upgrading my 10 year old PC to a shiny new machine that idles at nearly 30GHz and has 32 cores.

That coffee-lake claims only a pathetic 3.6GHz and 4 cores. Which fits the graph that shows Moore's Law is dead on this page very well: https://www.weforum.org/agenda/2018/09/ ... oores-law/

Anyway, we won't know for sure until somebody runs one of our multi-core fibo(4784969) programs on a coffee-lake.

Anyone here got a coffee-lake?

jahboater
Posts: 4462
Joined: Wed Feb 04, 2015 6:38 pm

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 8:30 am

Heater wrote:
Fri Apr 19, 2019 8:03 am
That coffee-lake claims only a pathetic 3.6GHz and 4 cores. Which fits the graph that shows Moore's Law is dead on this page very well: https://www.weforum.org/agenda/2018/09/ ... oores-law/
Its 8 cores and "up to" 5GHz with 16MB L2 cache.

Intel gave up increasing clock speeds long ago, but I think you will find the IPC, and the actual work throughput, of these 9th gen chips is many times more than our old 3rd gen ones.

I'll wait for 10nm AVX512 "Cannonlake" or possibly "Sunny Cove" which sounds a bit nicer, before I buy.
Last edited by jahboater on Fri Apr 19, 2019 8:33 am, edited 1 time in total.

ejolson
Posts: 3073
Joined: Tue Mar 18, 2014 11:47 am

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 8:32 am

jahboater wrote:
Fri Apr 19, 2019 7:23 am
Try a coffee-lake chip to see moores law still working ...
https://www.intel.com/content/www/us/en ... 9900k.html
I failed to find runtimes for any of our Fibonacci codes at that link.

Could anyone with a recently-built i9 gaming rig stop avoiding Basic and between high scores boot Linux? A report of Fibonacci runtimes would be really appreciated.

Heater
Posts: 12699
Joined: Tue Jul 17, 2012 3:02 pm

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 9:41 am

jahboater,
Its 8 cores and "up to" 5GHz with 16MB L2 cache.
Exactly. 8 cores is far short of the 32 it would need to be on the Moore's Law curve. "Up to" 5GHz is far short of the predicted 30GHz. R.I.P. Moore's Law.
Intel gave up increasing clock speeds long ago,
They had to. The limits of Denard scaling stopped them going any higher.
I think you will find the IPC, and the actual work throughput, of these 9th gen chips is many times more than our old 3rd gen ones.
Perhaps. Like I say, we won't know to till we get the fibo(4784969) results in.
I'll wait for 10nm AVX512 "Cannonlake" or possibly "Sunny Cove" which sounds a bit nicer, before I buy.
I'm going to blow my upgrade money on Raspberry Pi, FPGA boards, anything RISC V, electronics toys...

jalih
Posts: 64
Joined: Mon Apr 15, 2019 3:54 pm

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 5:44 pm

Thanks to John, I got result from 8th programming language version of fibo(4784969) running on real RPI hardware (Raspberry Pi 3 B):

Code: Select all

[email protected]:~/rpi8th/rpi32 $ time ./fibo
1000000 digits:
1072739564180047722936481359622500432190 upper 40 digits
3407167474856539211500699706378405156269 lower 40 digits
1946 msec

real   0m2.090s
user   0m2.044s
sys   0m0.040s
[email protected]:~/rpi8th/rpi32 $

ejolson
Posts: 3073
Joined: Tue Mar 18, 2014 11:47 am

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 5:57 pm

Heater wrote:
Fri Apr 19, 2019 9:41 am
I'm going to blow my upgrade money on Raspberry Pi, FPGA boards, anything RISC V, electronics toys...
Here is a table of Basic Calculator timings still missing any i9 results for the Fibonacci code.

Code: Select all

Basic Calculator Fibonacci Challenge

PROCESSOR             TIME   RATIO
Pi 3B+             126.161    3.15
Pi 3B              147.222    2.69
Pi 2B BCM2836      236.217    1.68
Pi Zero            271.928    1.46
Pi B+              397.463    1.00
Pentium 3 650Mhz   351.515    1.13
Athlon 1400Mhz     142.700    2.79
Odroid C2          105.391    3.77
Pentium 4 2.4Ghz   101.810    3.90
Celeron 2955U       72.583    5.48
Athlon 64X2 5400+   57.409    6.92
i7 2600K            36.363   10.93
Xeon E5-2620v3      33.278   11.94
Ryzen 7 Pro 1700    31.296   12.70
Xeon Gold 6126      30.924   12.85
Epyc 7371           30.691   12.95
i7 3770K            30.242   13.14
i5 8265U            30.048   13.23
I suspect the i9 would manage to complete the calculation in under 30 seconds, but I wonder how much less. When Moore's law works like this, why avoid Basic?
Last edited by ejolson on Thu Apr 25, 2019 11:40 pm, edited 1 time in total.

hippy
Posts: 5367
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Why Avoid BASIC on RPi?

Fri Apr 19, 2019 6:26 pm

jahboater wrote:
Fri Apr 19, 2019 4:42 am
Pi3B+

Code: Select all

$ time ./fibo.bc | tail -c32
4856539211500699706378405156269

real	2m6.161s
user	2m6.106s
sys	0m0.186s
I converted the bc to Python and ran that on my 3B (non-plus) -

Code: Select all

[email protected]:~/dummy $ time python bc.py  | tail -c32
4856539211500699706378405156269

real    6m13.783s
user    6m13.695s
sys     0m0.040s

Code: Select all

fiboA = 0
fiboB = 0
def Fast_Fibonacci(n):
  global fiboA
  global fiboB
  if n == 0:
    fiboA = 0
    fiboB = 1
    return 0
  y = Fast_Fibonacci(n >> 1)
  if n & 1:
    t = fiboA + fiboA + fiboB
    fiboA *= t
    fiboB *= t
    if (n & 3) == 1 : fiboA += 1
    else            : fiboA -= 1
  else:
    t = fiboB + fiboB - fiboA
    fiboA *= t
    fiboB *= t
    if n & 3 : fiboB += 1
    else     : fiboB -= 1
  return fiboA

print(Fast_Fibonacci(4784969))
But the most interesting thing is to run it with "n=Fast_Fibonacci(4784969)" so it calculates but doesn't print anything -

Code: Select all

[email protected]:~/dummy $ time python bc.py

real    0m17.699s
user    0m17.668s
sys     0m0.030s
That's comparable to my PC where the Python takes 2 minutes with output redirected to a file, but just five seconds for the assignment. The Pi's consistently three times slower in both cases. Which matches other benchmark testing I've done.

So one could say that we're not actually benchmarking the algorithm or the language at all, mostly timing how long it takes some in-built library to output a big number.

Return to “Off topic discussion”