Raspberry BASIC

Author Topic: SALC Ubuntu 64  (Read 1415 times)

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 160
    • View Profile
    • ScriptBasic
Re: SALC Ubuntu 64
« Reply #15 on: December 17, 2019, 03:36:12 AM »
JavaScript (Ubuntu 64 RPi 4B 4GB)

Code: Javascript
  1. // JavaScript - 1mil4.js
  2.  
  3. function reverseString(str){
  4.     let strn ="";
  5.     for(let char of str){
  6.         strn = char + strn;
  7.     }
  8.     return strn;
  9. }
  10.  
  11. var s = "";
  12. var t = "";
  13. var a = [1000001];
  14.  
  15. for (x = 1; x <= 1000000; x++) {
  16.   s += String.fromCharCode(((x - 1) % 26) + 65);
  17.   a[x] = x;
  18.   if(s.length == 26) {
  19.         t += s;
  20.         s = "";
  21.   }
  22. }
  23.  
  24. r = reverseString(t);
  25.  
  26. console.log("r LEN: " + r.length);
  27. console.log("Front: " + r.substring(0, 26));
  28. console.log("Back:  " + r.substring(-0, 26));
  29. console.log("UBVal: " + a[1000000]);
  30.  


ubuntu@rpi4b:~/salc/javascript-dev$ timex node 1mil4.js
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.97user 0.21system 0:01.20elapsed 98%CPU (0avgtext+0avgdata 118448maxresident)k
88inputs+0outputs (1major+27106minor)pagefaults 0swaps
ubuntu@rpi4b:~/salc/javascript-dev$

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 160
    • View Profile
    • ScriptBasic
Re: SALC Ubuntu 64
« Reply #16 on: December 17, 2019, 05:15:02 AM »
I split the topic into 4  groups

  • Just REM
  • One Mil Dash
  • SALC (String Array Language Challenge) Rasbain 32 bit on the RPi 4B 4GB
  • SALC Ubuntu 64 bit on the RPi 4B 4GB

A fifth round might be each language has to create a simple GUI. (not a popup message box) Maybe a login dialog.
« Last Edit: December 17, 2019, 05:26:20 AM by John Spikowski »
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 160
    • View Profile
    • ScriptBasic
Re: SALC Ubuntu 64
« Reply #17 on: December 18, 2019, 04:07:10 AM »
Nim 1,1,1 (Ubuntu 64 RPi 4B 4GB)

Code: Text
  1. # Nim 1.1.1 - onemil4.nim
  2.  
  3. proc reverse*(str: string): string =
  4.   result = ""
  5.   for index in countdown(str.high, 0):
  6.     result.add(str[index])
  7.  
  8. type
  9.     milarray = array[1000001, int]
  10.  
  11. var
  12.     s = ""
  13.     t = ""
  14.     r:string
  15.     a:milarray
  16.  
  17. for x in 0..1000000:
  18.     a[x] = x
  19.  
  20.     s &= chr((x mod 26) + 65)
  21.  
  22.     if s.len == 26:
  23.         t &= s
  24.         s = ""
  25.  
  26.  
  27. r = t.reverse
  28. echo "r Len: ",r.len
  29. echo "Front: ",r[0..25]
  30. echo "Back:  ",r[r.len-26..r.len-1]
  31. echo "UBVal: ",a[1000000]
  32.  


ubuntu@rpi4b:~/salc/nim-dev$ timex ./onemil4
r Len: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.04user 0.03system 0:00.07elapsed 98%CPU (0avgtext+0avgdata 14136maxresident)k
0inputs+0outputs (0major+3290minor)pagefaults 0swaps
ubuntu@rpi4b:~/salc/nim-dev$

« Last Edit: December 18, 2019, 02:21:59 PM by John Spikowski »
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 160
    • View Profile
    • ScriptBasic
Re: SALC Ubuntu 64
« Reply #18 on: December 19, 2019, 08:36:36 AM »
JADE C++ (Ubuntu 64 RPi 4B 4GB)

Code: C++
  1. #include <jade.hpp>
  2.  
  3. MAIN
  4.     STRING s,t,r;
  5.     ARRAY<int> a;
  6.  
  7.     FOR( VAR x = 0 TO x<1000001 STEP x++ ) DO
  8.         a.push_back(x);
  9.         s += (CHAR)(x%26)+65;
  10.  
  11.         IF ( LEN(s) == 26 ) THEN
  12.             t += s;
  13.             s = "";
  14.         END
  15.     END
  16.  
  17.     r = REVERSE$(t);
  18.  
  19.     PRINT("r LEN: ",LEN(t));
  20.     PRINT("Front: ", LEFT$(r,26));
  21.     PRINT("Back:  ", RIGHT$(r,26));
  22.     PRINT("UBVal: ",a[1000000]);
  23. END
  24.  


riveraa@rpi:~/Projects/jade$ timex ./mil64
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.05user 0.01system 0:00.07elapsed 98%CPU (0avgtext+0avgdata 10136maxresident)k
0inputs+0outputs (0major+3069minor)pagefaults 0swaps

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 160
    • View Profile
    • ScriptBasic
Re: SALC Ubuntu 64
« Reply #19 on: December 19, 2019, 10:29:19 PM »
GO (Ubuntu 64 RPi 4B 4GB)

Code: Go
  1. // GO - 1mil4.go - AIR
  2.  
  3. package main
  4.  
  5. import (
  6.     "fmt"
  7.     "strings"
  8. )
  9.  
  10. // Reverse returns its argument string reversed rune-wise left to right.
  11. // From: https://github.com/golang/example/blob/master/stringutil/reverse.go
  12. func Reverse(s string) string {
  13.     r := []rune(s)
  14.     for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
  15.         r[i], r[j] = r[j], r[i]
  16.     }
  17.     return string(r)
  18. }
  19.  
  20. func main() {
  21.     var s strings.Builder
  22.     var r = ""
  23.     var t strings.Builder
  24.     var a [1000001]int
  25.  
  26.     for x := 0; x < 1000001; x++ {
  27.         a[x] = x
  28.  
  29.         s.WriteByte(byte((x % 26) + 65))
  30.  
  31.         if s.Len() == 26 {
  32.             t.WriteString(s.String())
  33.             s.Reset()
  34.         }
  35.     }
  36.  
  37.     r = Reverse(t.String())
  38.  
  39.     fmt.Println("r LEN: ", len(r))
  40.     fmt.Println("Front: ", r[0:26])
  41.     fmt.Println("Back:  ", r[len(r)-26:])
  42.     fmt.Println("UBVal: ", a[1000000])
  43.  
  44. }
  45.  


ubuntu@rpi4b:~/salc/go-dev$ go build 1mil4.go
ubuntu@rpi4b:~/salc/go-dev$ ls -l
total 1932
-rwxr-xr-x 1 ubuntu ubuntu 2123629 Dec 19 14:26 1mil4
-rw-r--r-- 1 ubuntu ubuntu     887 Dec 19 14:25 1mil4.go
ubuntu@rpi4b:~/salc/go-dev$ timex ./1mil4
r LEN:  999986
Front:  ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:   ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal:  1000000
0.11user 0.02system 0:00.12elapsed 109%CPU (0avgtext+0avgdata 19272maxresident)k
0inputs+0outputs (0major+4599minor)pagefaults 0swaps
ubuntu@rpi4b:~/salc/go-dev$

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 160
    • View Profile
    • ScriptBasic
Re: SALC Ubuntu 64
« Reply #20 on: December 21, 2019, 04:35:48 AM »
8th (Ubuntu 64 RPi 4B 4GB)

Code: Text
  1. 1000000 constant LIMIT
  2.  
  3. a:new 0 a:push var, a
  4. 0 b:new true b:writable var, s
  5. 0 b:new true b:writable var, t
  6.  
  7.  
  8. : iterate
  9.   s @ "" 2 pick n:1- 26 n:mod 65 n:+ s:+ b:append
  10.   b:len 26 n:< not if
  11.     t @ swap b:append drop
  12.     0 b:new true b:writable s !
  13.   else
  14.     drop
  15.   then
  16.   a:push ;
  17.  
  18. : app:main
  19.   a @ ' iterate 1 LIMIT loop
  20.   t @ b:rev >s s:len "r LEN: %d\n" s:strfmt .
  21.   dup 26 s:lsub "Front: %s\n" s:strfmt .
  22.   26 s:rsub "Back:  %s\n" s:strfmt .
  23.   LIMIT a:@ nip "UBVal: %d\n" s:strfmt .
  24.   bye ;
  25.  


ubuntu@rpi4b:~/salc/8th-dev$ timex ./1mil4
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
1.00user 0.10system 0:01.12elapsed 98%CPU (0avgtext+0avgdata 66508maxresident)k
0inputs+0outputs (0major+15444minor)pagefaults 0swaps
ubuntu@rpi4b:~/salc/8th-dev$

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 160
    • View Profile
    • ScriptBasic
Re: SALC Ubuntu 64
« Reply #21 on: December 21, 2019, 08:18:16 AM »
Free Pascal (Ubuntu 64 RPi 4B 4GB)

Code: Pascal
  1. // Free Pascal -1mil4 - AIR
  2.  
  3. program mil;
  4.  
  5. Uses StrUtils;
  6.  
  7. var
  8.     s:AnsiString;
  9.     t:AnsiString;
  10.     c:AnsiChar;
  11.     a:array[0..1000001] of int32;
  12.     x:int32;
  13. begin
  14.     s := '';
  15.     t := '';
  16.     for x := 0 to 1000001 do
  17.     begin
  18.         c :=  chr( (x mod 26)+65 );
  19.         a[x] := x;
  20.         s += c;
  21.         if Length(s) = 26 then
  22.         begin
  23.             t += ReverseString(s);
  24.             s := '';
  25.         end;
  26.     end;
  27.  
  28.     writeln( 'r len: ', Length(t) );
  29.     writeln( 'Front: ', LeftStr(t,26) );
  30.     writeln( 'Back:  ', RightStr(t,26) );
  31.     writeln( 'UBVal: ', a[1000000]);
  32. end.
  33.  


riveraa@rpi:~/Projects/fpc/1mil3$ fpc -XX -CX -O3 mil64.pas
Free Pascal Compiler version 3.0.4+dfsg-22 [2019/01/24] for aarch64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for AArch64
Compiling mil64.pas
Assembling mil
Linking mil64
31 lines compiled, 0.4 sec

riveraa@rpi:~/Projects/fpc/1mil3$ timex ./mil64
r len: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.15user 0.02system 0:00.17elapsed 98%CPU (0avgtext+0avgdata 5616maxresident)k
0inputs+0outputs (0major+1423minor)pagefaults

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 160
    • View Profile
    • ScriptBasic
Re: SALC Ubuntu 64
« Reply #22 on: December 21, 2019, 08:22:20 AM »
Rust (Ubuntu 64 RPi 4B 4GB)

Code: Text
  1. // Rust - 1mil4 - AIR
  2.  
  3. fn main() {
  4.     let mut s = "".to_string();
  5.     let mut t = "".to_string();
  6.     let mut a = [0;1000001];
  7.  
  8.     for x in 0..1000001 {
  9.         a[x] = x;
  10.         let b   = ( x%26 ) as u8;
  11.         let c = ( b+65 ) as char;
  12.         s.push( c );
  13.         if s.len() == 26 {
  14.             let reversed: String = s.chars().rev().collect();
  15.             t.push_str( &reversed );
  16.             s.clear();
  17.         }
  18.     }
  19.     println!( "r LEN: {}",  t.len() );
  20.     println!( "Front: {}",  &t[..26] );
  21.     println!( "Back:  {}",  &t[t.len()-26..]);
  22.     println!( "UBVal: {}",  a[1000000] );
  23.  
  24. }
  25.  


riveraa@rpi:~/Projects/rust/1mil3$ rustc -O mil64.rs

riveraa@rpi:~/Projects/rust/1mil3$ timex ./mil64
r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.02user 0.01system 0:00.04elapsed 100%CPU (0avgtext+0avgdata 10440maxresident)k
0inputs+0outputs (0major+2371minor)pagefaults 0swaps

ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 160
    • View Profile
    • ScriptBasic
Re: SALC Ubuntu 64
« Reply #23 on: December 21, 2019, 08:32:48 AM »
Current results of the Ubuntu 64 bit and Rasbain 32 bit String Array Language Challenge on the RPi 4B 4GB,

« Last Edit: December 22, 2019, 08:56:30 PM by John Spikowski »
ScriptBasic Project Manager/Facilitator

AIR

  • BASIC Developer
  • *
  • Posts: 16
  • Code Jockey
    • View Profile
Re: SALC Ubuntu 64
« Reply #24 on: December 22, 2019, 06:04:08 AM »
Lua5.3

Code: Lua
  1. a = {}
  2. local s = ""
  3. local t = {""}
  4.  
  5. for i = 0,1000000 do
  6.         a[i] = i
  7.         local c = (i % 26)
  8.         s = s .. string.char(c + 65)
  9.         if c == 25 then
  10.                 table.insert(t, string.reverse(s))
  11.                 s = ""
  12.         end
  13. end
  14.  
  15. local r = table.concat(t)
  16. print("r LEN: ", #r)
  17. print("Front: ", string.sub(r,1,26))
  18. print("Back:  ", string.sub(r,-26))
  19. print("UBVal: ", a[1000000])
  20.  

riveraa@rpi:~/Projects/lua$ timex lua mil.lua
r LEN:    999986
Front:    ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:     ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal:    1000000
0.61user 0.02system 0:00.64elapsed 99%CPU (0avgtext+0avgdata 20812maxresident)k
0inputs+0outputs (0major+4981minor)pagefaults 0swaps


AIR.

AIR

  • BASIC Developer
  • *
  • Posts: 16
  • Code Jockey
    • View Profile
Re: SALC Ubuntu 64
« Reply #25 on: December 23, 2019, 04:50:25 AM »
VALA

Code: Vala
  1. int main (string[] args) {
  2.         var a = new int[1000000];
  3.         var s = new StringBuilder();
  4.         var t = new StringBuilder();
  5.         int c;
  6.  
  7.         for (int x  = 0; x < 1000001; x++) {
  8.                 a[x] = x;
  9.                 c = x % 26;
  10.  
  11.                 s.append_c( (char)c + 65);
  12.  
  13.                 if ( c == 25) {
  14.                         t.append(s.str.reverse());
  15.                         s.truncate();
  16.                 }
  17.         }
  18.  
  19.         string r = t.str;
  20.  
  21.         stdout.printf("r LEN: %d\n",r.length);
  22.         stdout.printf("Front: %s\n",r.substring(0,26));
  23.         stdout.printf("Back:  %s\n", r.substring(r.length-26,26));
  24.         stdout.printf("UBVal: %d\n", a[1000000]);
  25.         return 0;
  26. }
  27.  

riveraa@rpi:~/Projects/vala$ valac -X -O3 mil64.vala

r LEN: 999986
Front: ZYXWVUTSRQPONMLKJIHGFEDCBA
Back:  ZYXWVUTSRQPONMLKJIHGFEDCBA
UBVal: 1000000
0.03user 0.00system 0:00.03elapsed 97%CPU (0avgtext+0avgdata 7704maxresident)k
0inputs+0outputs (0major+1581minor)pagefaults 0swaps


AIR.