Author Topic: RaspberryBASIC.org Forum  (Read 2010 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2875
    • ScriptBasic Open Source Project
RaspberryBASIC.org Forum
« on: November 25, 2019, 06:45:24 PM »
I have been ban from the RPi forum for giving a moderator my opinion what their job should be.  >:(

I'm now posting on the RaspberryBASIC.org forum with my RPi efforts. If you would like to join us there, register to be a member.

I created a challenge that tests a common program among 11 different languages. Attached is the results of that challenge. The code for each can be found on the RaspberryBASIC.org forum.
« Last Edit: November 26, 2019, 12:55:17 AM by John »

Offline AIR

  • BASIC Developer
  • Posts: 740
Re: RaspberryBASIC.org Forum
« Reply #1 on: November 26, 2019, 07:52:19 AM »
Your bash code is doing string>int conversions.

I ran your original code on my macbook laptop (i5):

Middle
Plus:   1000000
Minus:  0

real    0m20.839s
user    0m19.425s
sys    0m1.391s


Then I ran an updated version where I eliminated the conversions:

Middle
Plus:   1000000
Minus:  0

real    0m16.380s
user    0m15.342s
sys    0m1.025s


The above were with Bash 3.2.57, which comes standard on macOS 10.13.6

Finally, I ran the updated script using Bash 5.0.11:

Middle
Plus:   1000000
Minus:  0

real    0m10.185s
user    0m10.060s
sys    0m0.108s


Updated script:

Code: Bash
  1. declare -i accum=0
  2. declare -i milvar=1000000
  3.  
  4. for i in {1..1000000}
  5. do
  6.   ((++accum))
  7.   ((--milvar))
  8.   if (( $accum == $milvar ));
  9.     then
  10.       echo "Middle"
  11.   fi
  12. done
  13.  
  14. echo "Plus:  " $accum
  15. echo "Minus: " $milvar

AIR.

PS:  For giggles, I ran the updated script on my local Debian server (i7, Bash 5.0.3):

Middle
Plus:   1000000
Minus:  0

real    0m3.722s
user    0m3.665s
sys    0m0.057s


Didn't run this on my Pi, which is a 3B model and slow as crap...LOL


Offline John

  • Forum Support / SB Dev
  • Posts: 2875
    • ScriptBasic Open Source Project
Re: RaspberryBASIC.org Forum
« Reply #2 on: November 26, 2019, 10:00:28 AM »
Thanks AIR for the updated Bash script. I'll update the challenge with your submission. It would be great if you join us on the RasperryBASIC.org forum. We could use a mentor of your skill level.

I'm looking for Ruby, Rust and 8th submissions that are run on a RPi 4B. I can run the 8th submission if a binary is attached along with the source.

Update: I didn't realize Ruby comes pre-installed on the RPi.

« Last Edit: November 28, 2019, 11:18:03 AM by John »

Offline jalih

  • Advocate
  • Posts: 74
Re: RaspberryBASIC.org Forum
« Reply #3 on: November 28, 2019, 06:36:51 AM »

I'm looking for Ruby, Rust and 8th submissions that are run on a RPi 4B. I can run the 8th submission if a binary is attached along with the source.

Here is a 8th version using just the stack...
Code: [Select]
: plus-minus
  n:1+
  swap
  n:1-
  swap
  2dup n:= if
    "Middle\n" .
  then ;

: app:main
  1000000 0
  ' plus-minus 1000000 times
  "Plus: %d\nMinus: %d\n" s:strfmt .
  bye ;

RPI binary available here

Offline John

  • Forum Support / SB Dev
  • Posts: 2875
    • ScriptBasic Open Source Project
Re: RaspberryBASIC.org Forum
« Reply #4 on: November 28, 2019, 09:40:34 AM »
Thanks Jalih for the 8th submission! I'll update the forum and chart with your submission. Any chance of a round 3 submission that addresses arrays and strings?

Curious. Is your name pronounced like the month of July?
« Last Edit: November 28, 2019, 10:25:03 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2875
    • ScriptBasic Open Source Project
Re: RaspberryBASIC.org Forum
« Reply #5 on: November 29, 2019, 01:28:22 PM »
Hi AIR,

Do you have time to slap together a C submission for the third round? Maybe some pointer magic would make it scream.


Offline jalih

  • Advocate
  • Posts: 74
Re: RaspberryBASIC.org Forum
« Reply #6 on: November 30, 2019, 04:44:21 AM »
Thanks Jalih for the 8th submission! I'll update the forum and chart with your submission. Any chance of a round 3 submission that addresses arrays and strings?

Curious. Is your name pronounced like the month of July?

Here is my round 3 submission... I used buffer to build string for speed as string concatenation is quite slow, as you are copying stuff around a lot.

Code: [Select]
1000000 constant LIMIT
LIMIT dup 26 n:mod n:- constant SLICE

LIMIT b:new true b:writable b:clear var, b
a:new 0 a:push var, a

: iterate
  dup >r n:1- dup 26 n:mod 65 n:+ b:!
  a @ r> a:push drop ;

: app:main
  b @ ' iterate 1 LIMIT loop
  0 SLICE b:slice b:rev >s
  s:len "r LEN: %d\n" s:strfmt .
  dup 26 s:lsub "Front: %s\n" s:strfmt .
  26 s:rsub "Back:  %s\n" s:strfmt .
  a @ LIMIT a:@ nip "UBVal: %d\n" s:strfmt .
  bye ;

RPI binary is available here

My name is pronounced more like: ja-li

Offline John

  • Forum Support / SB Dev
  • Posts: 2875
    • ScriptBasic Open Source Project
Re: RaspberryBASIC.org Forum
« Reply #7 on: November 30, 2019, 09:02:59 AM »
The whole purpose of round 3 is to see how well the language does with strings. I was hoping for some garbage collection along the way. Using a static buffer defeats the purpose.

Steps:

1. Build a character
2  Build alphabet string
3. Apend to result string
4. Reverse result string
« Last Edit: November 30, 2019, 10:00:21 AM by John »

Offline AIR

  • BASIC Developer
  • Posts: 740
Re: RaspberryBASIC.org Forum
« Reply #8 on: November 30, 2019, 10:28:51 AM »
Not sure why in the Python submission you're using Numpy to create a sized and initialized list.

You can simply do:

Code: Python
  1. a = [None] * 1000001

AIR.

Offline jalih

  • Advocate
  • Posts: 74
Re: RaspberryBASIC.org Forum
« Reply #9 on: November 30, 2019, 10:35:34 AM »
The whole purpose of round 3 is to see how well the language does with strings. I was hoping for some garbage collection along the way. Using a static buffer defeats the purpose.

Steps:

1. Build a character
2  Build alphabet string
3. Apend to result string
4. Reverse result string

Here is a version using strings instead of a buffer. I still convert the end result string to buffer, reverse and convert back to string. String reverse was very slow with 8th as it uses UTF8 strings. Developer of the 8th added optimization for the next version of 8th, if the string is just ASCII. Programming languages using ascii buffers for strings have a huge benefit in this challenge (remember that UTF-8 can have 1 to 4 bytes per character).

Code: [Select]
1000000 constant LIMIT

a:new 0 a:push var, a
"" var, s
"" var, t

: rev  \ s -- s
  b:new b:rev >s ;

: iterate
  s @ over n:1- 26 n:mod 65 n:+ s:+ s !
  s @ s:len 26 n:< not if
    t @ swap s:+ t !
    "" s !
  else
    drop
  then
  a:push ;

: app:main
  a @ ' iterate 1 LIMIT loop
  t @ rev s:len "r LEN: %d\n" s:strfmt .
  dup 26 s:lsub "Front: %s\n" s:strfmt .
  26 s:rsub "Back:  %s\n" s:strfmt .
  LIMIT a:@ nip "UBVal: %d\n" s:strfmt .
  bye ;

I updated the file in my previous download link, if you like to test the performance
« Last Edit: November 30, 2019, 10:44:56 AM by jalih »

Offline John

  • Forum Support / SB Dev
  • Posts: 2875
    • ScriptBasic Open Source Project
Re: RaspberryBASIC.org Forum
« Reply #10 on: November 30, 2019, 11:08:57 AM »
Thanks Jalih for the updated submission that is more inline with the challenge.

Thanks AIR for the Python optimization.
« Last Edit: November 30, 2019, 11:14:07 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 2875
    • ScriptBasic Open Source Project
Re: RaspberryBASIC.org Forum
« Reply #11 on: November 30, 2019, 01:13:54 PM »
AIR,

Your  Python optimization doesn't seem to work.

Code: Python
  1. # Python 3 - 1mil3.py
  2.  
  3. s = ""
  4. t = ""
  5. a = [None] * 1000001
  6.  
  7. for x in range(1000000):
  8.   s += chr(((x) % 26) + 65)
  9.   a[x] = x
  10.   if len(s) == 26:
  11.     t += s
  12.     s = ""
  13.  
  14. r = "".join(reversed(t))
  15.  
  16. print("r LEN: {}".format(len(r)))
  17. print("Front: {}".format(r[:26]))
  18. print("Back:  {}".format(r[-26:]))
  19. print("UBVal: {}".format(a[1000000]))
  20.  


pi@RPi4B:~/python-dev/examples $ /usr/bin/time python3 1mil3.py
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: None
1.84user 0.10system 0:01.94elapsed 99%CPU (0avgtext+0avgdata 32640maxresident)k
0inputs+0outputs (0major+7192minor)pagefaults 0swaps
pi@RPi4B:~/python-dev/examples $


Offline AIR

  • BASIC Developer
  • Posts: 740
Re: RaspberryBASIC.org Forum
« Reply #12 on: November 30, 2019, 01:25:00 PM »
try:

Code: Python
  1. for x in range(1000001):


Offline John

  • Forum Support / SB Dev
  • Posts: 2875
    • ScriptBasic Open Source Project
Re: RaspberryBASIC.org Forum
« Reply #13 on: November 30, 2019, 01:32:29 PM »
Nope.

Code: Python
  1. # Python 3 - 1mil3.py
  2.  
  3. s = ""
  4. t = ""
  5. for a in range(1000001):
  6.  
  7. for x in range(1000000):
  8.   s += chr(((x) % 26) + 65)
  9.   a[x] = x
  10.   if len(s) == 26:
  11.     t += s
  12.     s = ""
  13.  
  14. r = "".join(reversed(t))
  15.  
  16. print("r LEN: {}".format(len(r)))
  17. print("Front: {}".format(r[:26]))
  18. print("Back:  {}".format(r[-26:]))
  19. print("UBVal: {}".format(a[1000000]))
  20.  


pi@RPi4B:~/python-dev/examples $ /usr/bin/time python3 1mil3.py
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: None
1.88user 0.15system 0:02.04elapsed 99%CPU (0avgtext+0avgdata 32624maxresident)k
0inputs+0outputs (0major+7192minor)pagefaults 0swaps
pi@RPi4B:~/python-dev/examples $


Offline AIR

  • BASIC Developer
  • Posts: 740
Re: RaspberryBASIC.org Forum
« Reply #14 on: November 30, 2019, 01:33:23 PM »
You didn't make the change I posted.