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

Re: ScriptBasic

Fri Apr 12, 2019 4:07 pm

Just out of interest, I ran the equivalent of that code on a programmable calculator in about 1980 (No, it didn't run BASIC, so I'm a bit off topic here).

It took just over seven days to run.
Unreadable squiggle

jahboater
Posts: 5674
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: ScriptBasic

Fri Apr 12, 2019 4:36 pm

GCC with -O1 turns it upside down! (into a count down loop):

Code: Select all

    movl    $1000000, %eax
.L1:
    subl    $1, %eax
    jnz .L1
with -O2 or above it removes the whole thing of course, so the execution time is zero.

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

Re: ScriptBasic

Fri Apr 12, 2019 6:11 pm

ScriptBasic wrote:
Fri Apr 12, 2019 12:47 pm
Try the ScriptBasic example as a FOR / NEXT instead.
That is much faster. The Python equivalent 'for x in range(0,1000000):" is about the same for Python 3, slower for Python 2 ( which is what I expected ) -

Code: Select all

ScriptBasic : real 0m2.404s   user 0m2.403s
Python 3    : real 0m1.395s   user 0m1.383s
Python 2    : real 0m1.022s   user 0m1.001s
Python 2    : real 0m0.959s   user 0m0.938s - using xrange()
As with any language, getting to know what's best or fastest is all part of the learning curve and gaining experience. And please accept I wasn't criticising ScriptBasic; IME benchmarks rarely reflect real world use.

ScriptBasic seems to be quite impressive, a good and solid 'Basic', from what I have now read, though admittedly, so far, that's not a lot - I got sucked into the developer documents and wondering how it could fit in with Ultibo.

User avatar
bensimmo
Posts: 4575
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: ScriptBasic

Fri Apr 12, 2019 6:51 pm

Python 3.7 has a lot of speed improvements, making it faster than 2.7 for a lot of things, though load is still slower iirc.
But I guess it's a wait to Buster to do some proper benchmarks.
And for number crunching PyPy may be better
So you're only as fast as the version you use as well.

“Which is the fastest version of Python?” by Anthony Shaw https://link.medium.com/p2eo1PkKPV


Anyway, this is ScriptBasic hope it all goes well.
Make the Zero/Pi1 version usable for 256MB setups (if it matters). Though in the scheme of things (25Million total Pi) there are not many 256MB Pi's made.
If you see any speed improvements for the 3B/3B+ and it's worthwhile, go for a separate setup.
As long as the the answer is the same for the same code, then all is good.
It does stop cross Pi SD card swapping, is it possible to compile it for both in one, so it uses the best path depending on the device?

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

Re: ScriptBasic

Fri Apr 12, 2019 9:22 pm

bensimmo wrote:
Fri Apr 12, 2019 6:51 pm
Python 3.7 has a lot of speed improvements, making it faster than 2.7 for a lot of things, though load is still slower iirc.
In my experience, for the sort of code I write, which is mostly file parsing and the like, I find Python 3 about 30%-50% slower than Python 2. That's contrary to what is often said to be expected, and I don't dispute that Python 3 is indeed faster for some things, just for me and the things I do I have always found it far slower.

Being faster in a lot of things doesn't help when it's slower in the things one happens to be using. Blame for Python 3 being slower is usually put on the way integers are handled but it's file output which seems to be a major cause in slowness as far as I have compared things.

But bottom line, for Python, ScriptBasic, and any other interpretive languages, as long as the time it takes to execute is the right side of tolerable it's just fine. For high-speed execution; use something else, call C extensions, or go natively compiled.

Had ScriptBasic been readily available for a Pi earlier I might well have ended up using it rather than Python. It looks good to me, but a little too late now. Maybe I'll find some use for it.

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

Re: ScriptBasic

Sat Apr 13, 2019 12:09 am

Great article on what's under the Python covers. Startup and the cost of interfacing to C come at a price with Python. :?

This is an interpreter load/interpret/unload benchmark. The same code is use for ScriptBasic and Python.

Code: Select all

a=1

Code: Select all

pi@raspberrypi:~/sbrpi/examples $ time scriba let.sb

real	0m0.008s
user	0m0.008s
sys	0m0.000s
pi@raspberrypi:~/sbrpi/examples $ time python let.py

real	0m0.282s
user	0m0.067s
sys	0m0.033s
pi@raspberrypi:~/sbrpi/examples $ 
[code]

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

Re: ScriptBasic

Sat Apr 13, 2019 12:38 am

ScriptBasic wrote:
Sat Apr 13, 2019 12:09 am
This is an interpreter load/interpret/unload benchmark. The same code is use for ScriptBasic and Python.
For me the "a=1" ScriptBasic is about the same, but Python 2 is over three times quicker on my Pi 3B than what you are seeing; are you using a Zero ?

Code: Select all

pi@Pi3B:~/dummy $ time scriba let.sb
real    0m0.008s
user    0m0.007s
sys     0m0.002s

pi@Pi3B:~/dummy $ time python let.py
real    0m0.093s
user    0m0.082s
sys     0m0.012s

pi@Pi3B:~/dummy $ time python3 let.py
real    0m0.208s
user    0m0.198s
sys     0m0.010s

I got near on the same Python times calling a C extension to do the increment to a million as "a=1", so I suspect that's optimised itself away to nothing. I'll maybe take a look at how to stop C extension being optimising.

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

Re: ScriptBasic

Sat Apr 13, 2019 12:47 am

ScriptBasic seems to be quite impressive, a good and solid 'Basic', from what I have now read, though admittedly, so far, that's not a lot - I got sucked into the developer documents and wondering how it could fit in with Ultibo.
Ditto.
Ultibo has for me, reached the stage of needing a scripted language to move to the next level of UX.

Python has taken over from Basic as the goto scripted language and in the web world Javascript dominates.
Down the low end we see 32bit IoT devices now using Python and Basic.
I have different wireless modules that use both.

Pi's fit that area between Cortex M0 gadgets and Desktop boxes.
There is room for every language in that space.

UX, User Experience, are we as coders the end users?
If we make stuff sooner or later we have to let our babies go and leave home(lab) with their actually users and owners ;)
We not only have to think about our UX with languages but also the end users UX.
I'm learning a certain flexibility and capacity to change after leaving the lab is a desirable attribute.

From my start in the Pi world 7 years ago I am now full circle and back to scripted languages.
Compiled code just does not do everything.
How many gadgets do we buy now that fit in our pockets or on our wrists do not have upgrade capability?]
No one is a perfect coder or can think of everything the end user wants.
Just look how far Raspbian has come and still has to go.

Some end users are annoyed with locked in OS's and want Open Android, Open Fitbit, OpenWRT.....
Is it because we cannot trust these company's coders or their reasons for doing certain things.
I want the capability of changing stuff I spent my money on, I'm not the only one.

Why have I missed Basic on Pi's?
Sucked in on the new shiny Python?
I quickly found Python was not perfect.
Learn and use every language, add them all to the toolbox.
Hammers come in all sizes .
If ScriptBasic is faster than Python as it is looking then it is worth taking some practice swings.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

jahboater
Posts: 5674
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: ScriptBasic

Sat Apr 13, 2019 12:49 am

hippy wrote:
Sat Apr 13, 2019 12:38 am
I'll maybe take a look at how to stop C extension being optimising.
Declare n volatile should slow it right down.

Code: Select all

int
main( void )
{
  volatile int n = 0;
  while( n < 1000000 )
    ++n;
}

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

Re: ScriptBasic

Sat Apr 13, 2019 1:09 am

hippy wrote:
Sat Apr 13, 2019 12:38 am
I got near on the same Python times calling a C extension to do the increment to a million as "a=1", so I suspect that's optimised itself away to nothing.
Yup, with -O2 it was just loading 1000000 and returning.

With CFLAGS="-O0", and disassembling the C extension, as far as I can tell it is doing a full increment up to a million. And, yes, "intTo" was a typo for "incTo" :)

Code: Select all

uint intToMillion()
{
 a04:   e52db004        push    {fp}            ; (str fp, [sp, #-4]!)
 a08:   e28db000        add     fp, sp, #0
 a0c:   e24dd00c        sub     sp, sp, #12
  uint n = 0;
 a10:   e3a03000        mov     r3, #0
 a14:   e50b3008        str     r3, [fp, #-8]
  while ( n < 1000000 ) { n++; }
 a18:   ea000002        b       a28 <intToMillion+0x24>
 a1c:   e51b3008        ldr     r3, [fp, #-8]
 a20:   e2833001        add     r3, r3, #1
 a24:   e50b3008        str     r3, [fp, #-8]
 a28:   e51b3008        ldr     r3, [fp, #-8]
 a2c:   e59f2018        ldr     r2, [pc, #24]   ; a4c <intToMillion+0x48>
 a30:   e1530002        cmp     r3, r2
 a34:   9afffff8        bls     a1c <intToMillion+0x18>
  return n;
 a38:   e51b3008        ldr     r3, [fp, #-8]
}
 a3c:   e1a00003        mov     r0, r3
 a40:   e28bd000        add     sp, fp, #0
 a44:   e49db004        pop     {fp}            ; (ldr fp, [sp], #4)
 a48:   e12fff1e        bx      lr
And that's blindingly fast in comparison -

Code: Select all

Python 2        : real 0m1.022s   user 0m1.001s
Via C Extension : real 0m0.092s   user 0m0.071s
Which is good news because it means I haven't been wasting my time this last couple of days in learning how to create extensions.

I suppose I shouldn't be surprised given the Pi's clock speed.But I'm more used to using micros at 8MHz !

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

Re: ScriptBasic

Sat Apr 13, 2019 1:44 am

Gavinmc42 wrote:
Sat Apr 13, 2019 12:47 am
Ultibo has for me, reached the stage of needing a scripted language to move to the next level of UX.
Ultibo is great, especially if one wants 'zero boot time'. The trouble is it's Pascal, lacking the high-level application support I would like, and it's just too much effort to commit to; there's only so many plates one can keep spinning at a time.

I'm still after the holy grail of a 'boot to Python' Pi clone of the micro:bit, but 'boot to ScriptBasic' would be a good second option. And it would give ScriptBasic an immediate use case for the Pi; a sort of 'Bare Metal in Basic' option.

It looks like ScriptBasic should be reasonably straight forward to integrate into Ultibo for someone who knows how to do it, given it's designed to be embedded. Unfortunately I have other plates to spin at the moment.

User avatar
scruss
Posts: 3154
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: ScriptBasic

Sat Apr 13, 2019 3:35 am

hippy wrote:
Sat Apr 13, 2019 1:44 am
I'm still after the holy grail of a 'boot to Python' Pi clone of the micro:bit, …
here y'go, Arthur: boochow/micropython-raspberrypi: bare metal Raspberry Pi Zero / Zero W port of MicroPython
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

jahboater
Posts: 5674
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: ScriptBasic

Sat Apr 13, 2019 4:39 am

hippy wrote:
Sat Apr 13, 2019 1:44 am
I'm still after the holy grail of a 'boot to Python' Pi clone of the micro:bit, but 'boot to ScriptBasic' would be a good second option.
Another possibility might be to simply add "init=/usr/bin/python" to the file /boot/cmdline.txt
The Pi will then boot directly to the Python prompt.
No shell, no systemd, nothing but the kernel and Python.

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

Re: ScriptBasic

Sat Apr 13, 2019 5:18 am

Gavinmc42,
Down the low end we see 32bit IoT devices now using Python and Basic.
And Javascript:
https://www.espruino.com/
https://doc.qt.io/qt-5/qtquick-index.html
And Lua:
https://www.nodemcu.com/index_en.html
Compiled code just does not do everything.
I'm pretty sure you have not said what you meant there.
Learn and use every language, add them all to the toolbox.
No. Life is too short. Many of them are conceptually similar. Once you have learned one you are wasting your life if you have to lean another. For example PL/M, Pascal, Coral, Ada, C/C++.

I feel it's better to learn languages that have very different styles: Scheme, Forth, Go, Erlang, Javascript... That makes you think about programming in different ways.
Memory in C++ is a leaky abstraction .

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

Re: ScriptBasic

Sat Apr 13, 2019 8:40 am

Compiled code just does not do everything.

I'm pretty sure you have not said what you meant there.
Nope, I just said that to rattle some cages.
Complied code will do everything if you are good enough to think of everything and then good enough to code it ;)
JS, Lua, yep forgot them and........

Been messing about with Go, Rust, PonyC recently.
After using so many languages in the last 7 years I wonder what the flame wars are all about.
Big deal, just some syntax and punctuation differences ;)

I don't know enough about compilers so Jack Crenshaw is getting used.
After reading, er flicking through the Dragon book, yep I will never make a compiler like those.
But I could make a simple one that's good enough for me, just for fun.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

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

Re: ScriptBasic

Sat Apr 13, 2019 8:52 am

I feel it's better to learn languages that have very different styles: Scheme, Forth, Go, Erlang, Javascript... That makes you think about programming in different ways.
I think multi-language code challenges are a great way to see the advantages one language has over another.

My direction has been use ScriptBasic as a base and extension modues for additional functionality.

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

Re: ScriptBasic

Sat Apr 13, 2019 9:34 am

Gavinmc42,
Big deal, just some syntax and punctuation differences
Are you rattling cages again?

I think that was part of my point. At the bottom level of computing we have "sequence", "selection" and "iteration". That is to say statements, if..else.., and loops. With languages like PL/M, Pascal, Coral, Ada, C/C++, BASIC that is about all you get. With many and varied ways to say the same thing with different syntax. Learn one and you have learned them all.

But then there are languages that have a very different semantics. Their syntax carries different meaning. For example:

Forth - Emphasizes a stack based approach to program construction.

Lisp/Scheme - Have a syntax designed to easily express lists and operations on lists.

Scala/Haskell - Prioritize functional programming.

Javascript - Forces you into an event driven model.

Go - Is into processes and channels. The Tony Hoare "Communicating Sequential Process" model.

And so on. These semantically different languages get you thinking about how to build programs very differently.

Jack Crenshaw's "Let's Build a Compiler" series is great. I followed that through some years ago and ended up with a compiler for a C/Pascal like language, written in C, that generated executables for x86 and the Parallax Propeller micro-controller. Terrible big and slow executables with no optimization. But I was over the moon that I had managed to create a compiler and generate real code.

Like you I looked at things like the famous Dragon Book. I suspect nobody ever managed to write a compiler with only those for inspiration.
Memory in C++ is a leaky abstraction .

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

Re: ScriptBasic

Sat Apr 13, 2019 10:08 am

It looks like ScriptBasic should be reasonably straight forward to integrate into Ultibo for someone who knows how to do it, given it's designed to be embedded.
BINGO

Embed ScriptBasic in Python. 8-)

https://docs.python.org/2/c-api/

FWIW:

I wrote a JavaScript extension module for ScriptBasic based on the light weight V7 JS version. The problem is the library has been deprecated for another direction. I might post the extension module and a few examples I wrote using it to see if there is any interest expanding on it or forking the V7 code.

https://github.com/cesanta/v7

I restored from the archive on the ScriptBasic.org forum the thread I created for the JavaScript extension module.

https://www.scriptbasic.org/forum/index ... ml#msg1638

It JavaScript isn't your thing, I wrote a TinyScheme (LISP) extention module as well.

https://www.scriptbasic.org/forum/index ... ml#msg1408
Last edited by John_Spikowski on Sat Apr 13, 2019 12:29 pm, edited 8 times in total.

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

Re: ScriptBasic

Sat Apr 13, 2019 10:50 am

scruss wrote:
Sat Apr 13, 2019 3:35 am
hippy wrote:
Sat Apr 13, 2019 1:44 am
I'm still after the holy grail of a 'boot to Python' Pi clone of the micro:bit, …
here y'go, Arthur: boochow/micropython-raspberrypi: bare metal Raspberry Pi Zero / Zero W port of MicroPython
Thanks Sir Lancelot.

After the MicroPython team had been rather dismissive of creating a Bare Metal version for the Pi, which is understandable as they have their own boards to sell and their own interests to protect, it seemed it would fall to a third party to do port it and I wasn't expecting that any time soon, hadn't kept my eye on such developments.

It's therefore great to see 'boochow' took up that task, though I'm surprised he never thought to give that a mention here.

I'll obviously be giving it a spin to check it out so thanks for pointing me to that.

Added : That of course opened a new door to another circle of hell. The 'unix' port of MicroPython ( which runs under Raspbian ) builds out of the box, but the 'boochow' port does not. Now to find what dependencies I need and haven't been documented.
Last edited by hippy on Sat Apr 13, 2019 11:33 am, edited 1 time in total.

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

Re: ScriptBasic

Sat Apr 13, 2019 11:33 am

I gave up on the Microbit kiddie stuff and now use Adafruit's Arduino stuff on it.
The Microbit BT works fine and talks to Ultibo's BT.
I need to spend a few weeks on that combo and just make stuff.
Got a bunch of HID gadgets and robot controllers I want to make.

I missed that Micropython on baremetal Pi too.
First glance it is pretty basic, wonder if someone can get OpenVG working on it?
I might get around to real baremetal one day.
Big deal, just some syntax and punctuation differences

Are you rattling cages again?
Guilty ;)

All those languages came about because the user could not or did not like solving problems in another language.
Or just to show off :lol:
At cpu speeds these days user interfaces are fine written in script.
I installed tcl/tk on everything to test that theory.

I just made a new Raspbian USB stick with latest release and latest Laz/FPC and Ultibo.
Going to play with LIL and Partcl. ttps://zserge.com/blog/tcl-interpreter.html
After Crenshaw these are small enough for me to grasp.
I am just after a runtime script engine for OpenVG experiments, this is a good starting point.

Bingo, LIL just compiled and ran on a Pi.
After no issues on Windows and just debugger issues on Linux /Pi this will be my starting point in DIY interpreters.
They say you cannot understand compilers until you make your own, this is close enough for me :D

I'm not expecting great things from LIL, it did score pretty low on the benchmarks.
But unlike Props, Zero's run at 1GHz, it might be good enough.
I better hurry up, just found out Prop2 engineering samples are now real.

Now where was those SB install instructions, that's going on next.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

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

Re: ScriptBasic

Sat Apr 13, 2019 11:42 am

What is this "LIL" of which you speak?
Memory in C++ is a leaky abstraction .

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

Re: ScriptBasic

Sat Apr 13, 2019 11:50 am

Now where was those SB install instructions, that's going on next.
If SB means ScriptBasic then the runtime, doc pdf and ext. module examples were posted on the Off Topic board. The AppImage and DED on the ScriptBasic.org forum were built on the RPi 3 B and won't run on the Zero.

You will probably want to build SB from scratch so visit the sandbox (Gitlab CE repo) and use the cleanup branch.

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

Re: ScriptBasic

Sat Apr 13, 2019 12:19 pm

ScriptBasic wrote:
Sat Apr 13, 2019 10:08 am
It looks like ScriptBasic should be reasonably straight forward to integrate into Ultibo for someone who knows how to do it, given it's designed to be embedded.
BINGO

Embed ScriptBasic in Python. 8-)
Of course it doesn't have to be Ultibo. That's a good choice because it's a solid product and provides almost everything one needs for 'no OS' applications.

Anything else which supports Pi Bare Metal would do, though that might not have all that's needed or require more effort getting it to work. Circle seems to be quite comprehensive these days.

An example of embedding ScriptBasic in mainstream Python 2 or 3 via a C extension would be useful to have. That's probably the angle I am going to start with given extensions are what I'm currently working on.

If it can be embedded in MicroPython ( though a rather different C extension needed there ) then, if Bare Metal MicroPython runs on a Pi, that's a potential shortcut to getting Bare Metal ScriptBasic also on a Pi.

I'm not too fussed how it is done or how well it works to start with. Getting over the initial hurdle of having something which does run is the main thing.

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

Re: ScriptBasic

Sat Apr 13, 2019 12:24 pm

Heater wrote:
Sat Apr 13, 2019 11:42 am
What is this "LIL" of which you speak?
I would assume the "Little Interpreted Language" - http://runtimeterror.com/tech/lil

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

Re: ScriptBasic

Sat Apr 13, 2019 12:35 pm

ScriptBasic wrote:
Sat Apr 13, 2019 8:52 am
I think multi-language code challenges are a great way to see the advantages one language has over another.
Yes, but we should be using as a measure of 'advantage' something better than the time taken to count up to a million!

Return to “Other programming languages”