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

ScriptBasic

Thu Apr 11, 2019 10:59 pm

Last edited by ScriptBasic on Thu May 30, 2019 2:56 pm, edited 1 time in total.

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

Re: ScriptBasic

Fri Apr 12, 2019 2:06 am

ScriptBasic wrote:
Thu Apr 11, 2019 10:59 pm
I just ordered a RPI 3 B+. Is there a benefit to creating a separate ScriptBasic build for the 3 B+ or will the Zero build that is known to work on the 3 B+ do?
Maybe. There are significantly greater opportunities for a compiler to optimize code generated for ARMv7 compared to the ARMv6 instruction set. You will have to set the appropriate flags in the build scripts for the 3B+ to enable the additional optimisations and then check whether the resulting interpreter runs significantly faster to make having two separate binaries worth the trouble.

For most of the programs included with Raspbian a single binary compiled for ARMv6 is sufficient. I think the only exceptions to this rule are the web browsers, video encoders and mathematics libraries.

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

Re: ScriptBasic

Fri Apr 12, 2019 2:37 am

Thanks for the advice!

I will have to do some testing to see if it's worth having more than one build for the RPi.

I'm curious what was enabled in the RPi 3 B build that wouldn't allow it to run on the Zero?

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

Re: ScriptBasic

Fri Apr 12, 2019 3:53 am

It's simply a matter of CPU Architecture level. The Zero (and 1 series) use an ARMv6 CPU core. The older Pi2B uses four ARMv7 CPU cores. The newer Pi2B and the Pi3 series use an ARMv8 but running in ARMv7 compatibility mode. The compiler will default to building for the current CPU level. Most code compiled for the earlier CPUs will run on the later ones (only in 32-bit compatibility mode on the latest ones). But code for the new ones use instructions that the earlier ones don't have.

There are compiler flags to set the correct target CPU when building. I can't remember them offhand, but a quick search of the forums should find some posts with the details.
Signature is on holiday.

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

Re: ScriptBasic

Fri Apr 12, 2019 4:00 am

Most code compiled for the earlier CPUs will run on the later ones (only in 32-bit compatibility mode on the latest ones). But code for the new ones use instructions that the earlier ones don't have.
Good explanation of the 32/64 bit rationally.

http://www.raspberry-pi-geek.com/Archiv ... 4-bit-mode

A thread about 64 bit OSs here on the forum

viewtopic.php?t=208314

Ubuntu MATE for the Raspberry Pi Model B 2, 3 and 3+

From what I read, I can boot Ubuntu Mate 64 bit from a USB drive. This might be a better way to go now that the USB port can throttle at 1 gigabit. / second. The only gain is 64 bit variables. With only 1 GB of ram, 64 memory addeassability is unused.

Do you think if I built a 64 bit version of ScriptBasic for Ubuntu Mate on a RPi 3 B+, someone other than myself would use it?

Using Raspbain is like running sysWoW64.

gcc complaining about the -m64 option now makes sense.
Last edited by ScriptBasic on Fri Apr 12, 2019 6:35 am, edited 9 times in total.

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

Re: ScriptBasic

Fri Apr 12, 2019 4:25 am

ScriptBasic wrote:
Fri Apr 12, 2019 4:00 am
If I understand what you're saying is the Zero runs in 32 bit mode and the B 3 runs in 64 bit mode?
Sorry, perhaps I explained badly. No, they all run in 32-bit mode.

The ARMv8 can run in 64-bit or 32-bit mode, but as Raspbian is 32-bit that is the mode that all Pi's use (except when running some of the non-Raspian OSes that have been built for 64-bit running).

It is just that the later CPUs have extra 32-bit instructions (NEON and other features) that the earlier ones do not have. Compile on a 3B and the compiler will default to using those instructions. Compile on a Pi Zero and it won't use them as it knows they don't exist on that CPU.

Incidentally, Raspbian came about because the particular ARMv6 (ARM 1176ZJF) used in the Pi 1 had some hardware floating point instructions which most of the ARMv6 chips didn't have. This meant that the only Debian code that would run on the PI 1B was the armel architecture which didn't use hardware floating point at all. That ran very slowly. To use Debian armhf you needed an ARMv7. Thanks to a huge amount of work by Plugwash, Raspbian was born, which meant taking every package from Debian and recompiling it to work on the ARMv6 of the Pi 1B as armhf. Some tweaks were made to give even more speed improvements and some packages had to have the source modified to get them to compile. Mostly it is now automatic, but there is still a fair bit of checking and fixing to do every time that Debian update their source code.
Signature is on holiday.

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

Re: ScriptBasic

Fri Apr 12, 2019 5:22 am

WHY SHALL I USE RaspEX?
Eight Operating Systems are recommended by Raspberrypi.org. Among them Raspbian. RaspEX is faster, more useful and more fun to use. (In my opinion). One member at raspex.exton.se thought that running RaspEX was like running Raspberry on “steroids“. If you run Build 181015/181010 on a Raspberry Pi 3 B+ it's even faster.
RaspEX looks interesting.

User avatar
Gavinmc42
Posts: 2884
Joined: Wed Aug 28, 2013 3:31 am

Re: ScriptBasic

Fri Apr 12, 2019 6:03 am

Never heard of RaspEX, getting too many Pi OS's?

For the RP Foundation's mission to teach programming, 64bit is not needed.

But some of us like to use and learn 64bit coding too.
If you want to make an Aarch64 ARMv8 version of ScriptBasic, I'm sure Sakaki will be happy to add it to the Gentoo64 ebuilds.
I can see a use for both versions.

Then we can benchmark them ;)
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

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

Re: ScriptBasic

Fri Apr 12, 2019 7:27 am

ScriptBasic,
Eight Operating Systems are recommended by Raspberrypi.org. Among them Raspbian. RaspEX...
Where did you get that from?

I have never head of RaspEX before and cannot fond any place where Raspberry.pi org recommends it.

Looks like RaspEX might me useful if you want a television rather than a computer.
Last edited by Heater on Fri Apr 12, 2019 8:03 am, edited 1 time in total.

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

Re: ScriptBasic

Fri Apr 12, 2019 7:30 am

ScriptBasic wrote:
Fri Apr 12, 2019 5:22 am
WHY SHALL I USE RaspEX?
Eight Operating Systems are recommended by Raspberrypi.org. Among them Raspbian. RaspEX is faster, more useful and more fun to use. (In my opinion). One member at raspex.exton.se thought that running RaspEX was like running Raspberry on “steroids“. If you run Build 181015/181010 on a Raspberry Pi 3 B+ it's even faster.
RaspEX looks interesting.
Please learn to include the sources of the quotes you include in your posts.

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

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

Re: ScriptBasic

Fri Apr 12, 2019 7:32 am

ScriptBasic MAXINT function.

Code: Select all

PRINT MAXINT,"\n"
RPI 3 B

[email protected]:~/sbrpi/examples $ scriba maxint.sb
2147483647
[email protected]:~/sbrpi/examples $


Ubuntu 64 - AMD laptop

[email protected]:~/sb/examples$ scriba maxint.sb
9223372036854775807
[email protected]:~/sb/examples$

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

Re: ScriptBasic

Fri Apr 12, 2019 8:27 am

Looks like RaspEX might me useful if you want a television rather than a computer.
RaspEX is 64 bit Linux tuned for the RPi 3 B+. I haven't run on 32 bit Linux in over 10 years. Most mainstream Linux distribution no longer support 32 bit versions. i386 is your only treading water option.

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

Re: ScriptBasic

Fri Apr 12, 2019 8:34 am

ScriptBasic wrote:
Fri Apr 12, 2019 8:27 am
Looks like RaspEX might me useful if you want a television rather than a computer.
RaspEX is 64 bit Linux tuned for the RPi 3 B+. I haven't run on 32 bit Linux in over 10 years. Most mainstream Linux distribution no longer support 32 bit versions. i386 is your only treading water option.
This 64-bit distro for the Pi3 is my favourite ...
https://github.com/sakaki-/gentoo-on-rpi3-64bit
Fast and well engineered.

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

Re: ScriptBasic

Fri Apr 12, 2019 8:41 am

ScriptBasic wrote:
Fri Apr 12, 2019 4:00 am
Using Raspbain is like running sysWoW64.
No, its a proper native 32-bit distro.

I suggest you spend some time reading ARM's introduction to ARMv8:
http://infocenter.arm.com/help/topic/co ... ure_PG.pdf
gcc complaining about the -m64 option now makes sense.
There is no such option on ARM.
GCC on AArch64 will only compile for 64-bits as far as I can see.

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

Re: ScriptBasic

Fri Apr 12, 2019 8:42 am

Sounds great.

Of course there are many other 64 bit OS for the Pi around. I'm using Pi64 here: https://github.com/bamarni/pi64

What I use on my PC is of little consequence to what I use on systems like the Pi. For the vast majority of use cases a 32 bit OS on the Pi is just fine. I only went to pi64 so as to experiment with running a database cluster using CockroachDB.

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

Re: ScriptBasic

Fri Apr 12, 2019 9:33 am

Here are the Fibonacci numbers running 64 bit. (language and OS)

ScriptBasic
[email protected]:~/sb/examples/test$ time scriba fibonacci.sb
46368

real 0m0.269s
user 0m0.264s
sys 0m0.004s

Python
1st run:
[email protected]:~/sb/examples/test$ time python fibonacci.py
46368

real 0m0.787s
user 0m0.062s
sys 0m0.044s
[email protected]:~/s

2nd Run:
[email protected]:~/sb/examples/test$ time python fibonacci.py
46368

real 0m0.063s
user 0m0.055s
sys 0m0.008s

Bash
[email protected]:~/sb/examples/test$ time ./fibonacci.sh
46368

real 0m4.049s
user 0m4.043s
sys 0m0.004s

C
[email protected]:~/sb/examples/test$ time ./fibonacci
46368

real 0m0.005s
user 0m0.001s
sys 0m0.005s
[email protected]:~/sb/examples/test$

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

Re: ScriptBasic

Fri Apr 12, 2019 9:48 am

The second runs are usually faster because Linux retains the program in the disk cache.
Here you can see the disk activity is zero for the second run, because the disk blocks are all in the cache.

/usr/bin/time -f "Disk %I, Resident Memory %M, User CPU %U" python3 ./fibo.py
46368
Disk 7744, Resident Memory 6504, User CPU 1.05

/usr/bin/time -f "Disk %I, Resident Memory %M, User CPU %U" python3 ./fibo.py
46368
Disk 0, Resident Memory 6656, User CPU 1.00

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

Re: ScriptBasic

Fri Apr 12, 2019 10:01 am

All the other languages were repeatable.

Loading up and initializing a 10 MB chunk of code takes time.

https://dev.to/methane/how-to-speed-up- ... p-time-nkf

User avatar
Gavinmc42
Posts: 2884
Joined: Wed Aug 28, 2013 3:31 am

Re: ScriptBasic

Fri Apr 12, 2019 11:00 am

SB is 4 times faster than Python?
How does it compare against Lua and more importantly Luajit?

The SB fibo was compiled to intermediate code and then interpreted?
Not an ordinary basic Basic ;)
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

fanoush
Posts: 442
Joined: Mon Feb 27, 2012 2:37 pm

Re: ScriptBasic

Fri Apr 12, 2019 12:28 pm

ScriptBasic wrote:
Fri Apr 12, 2019 4:00 am
Using Raspbain is like running sysWoW64.
No, both kernel and userspace is 32bit, but with this guide viewtopic.php?t=232417 it is the other way around - there is 32bit main OS (runing on top of 64bit kernel) and you can run 64bit debian in a container next to main OS. Also downloadable here https://github.com/sakaki-/raspbian-nspawn-64

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

Re: ScriptBasic

Fri Apr 12, 2019 12:44 pm

Gavinmc42 wrote:
Fri Apr 12, 2019 11:00 am
SB is 4 times faster than Python?
As always; it depends on what one is doing. Using my simplistic benchmark, increment to a million, on a Pi 3B under Raspbian (32-bit) ...

Code: Select all

n = 0
while n < 1000000
  n = n + 1
wend

Code: Select all

ScriptBasic : real 0m5.289s   user 0m5.289s
Python 3    : real 0m1.509s   user 0m1.490s
Python 2    : real 0m0.974s   user 0m0.964s

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

Re: ScriptBasic

Fri Apr 12, 2019 12:47 pm

Try the ScriptBasic example as a FOR / NEXT instead.

Code: Select all

n = 0
FOR x = 1 to 1000000
  n += 1
NEXT
PRINT n, "\n"
Last edited by ScriptBasic on Fri Apr 12, 2019 12:56 pm, edited 1 time in total.

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

Re: ScriptBasic

Fri Apr 12, 2019 12:51 pm

hippy wrote:
Fri Apr 12, 2019 12:44 pm
As always; it depends on what one is doing. Using my simplistic benchmark, increment to a million, on a Pi 3B under Raspbian (32-bit) ...

Code: Select all

n = 0
while n < 1000000
  n = n + 1
wend
I bet a more sophisticated interpreter such as Javascript would just set n to one million and remove the loop, or even the entire program since it doesn't use the result (like C would).
Last edited by jahboater on Fri Apr 12, 2019 1:02 pm, edited 1 time in total.

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

Re: ScriptBasic

Fri Apr 12, 2019 12:59 pm

The SB fibo was compiled to intermediate code and then interpreted?
In a continuous segment of memory no less.

User avatar
RichardRussell
Posts: 415
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Fri Apr 12, 2019 3:52 pm

hippy wrote:
Fri Apr 12, 2019 12:44 pm

Code: Select all

ScriptBasic : real 0m5.289s   user 0m5.289s
Python 3    : real 0m1.509s   user 0m1.490s
Python 2    : real 0m0.974s   user 0m0.964s
For comparison the equivalent code running in BBC BASIC for SDL 2.0 took 3.9 seconds on a Pi 3B; changing the 'n' to 'n%' (signifying a 32-bit integer) reduced it to 2.1 seconds.

Return to “Other programming languages”