Author Topic: ScriptBasic for Android  (Read 42795 times)

kryton9

  • Guest
Re: ScriptBasic for Android
« Reply #30 on: May 15, 2012, 07:59:08 AM »
Glad you got it working under Linux.

support

  • Administrator
  • *****
  • Posts: 859
    • Script BASIC Open Source Project
Re: ScriptBasic for Android
« Reply #31 on: May 17, 2012, 09:48:23 PM »
For those wondering what a Facade is.

Quote
If you go to the SL4A API one of the things you notice is the word Facade at the end of each API.  Facade refers to a software design pattern.  A software design pattern is a generic reusable solution to a problem that occurs in a specific context in software design.  So, a facade software design pattern, represented by a facade is an object that provides a simplified interface to a larger body of code, like a class library.  As a developer you might want to do this to make the library more readable, and reduce dependencies of code on the inner workings of a given library.  In our case, the facade object is Android, and it provides a single, simple interface to the Android SDK, which is huge (relatively speaking).  The Android facade object provides a simple interface to a number of things including battery manager, camera functionality, media player, settings api, speech recognition api, web cam functionality just to name a few things.
Script BASIC Project Manager

kryton9

  • Guest
Benchmarking
« Reply #32 on: May 20, 2012, 11:12:26 AM »
Updated the attachment to the latest working python and scriptbasic scripts for benchmarking. Thanks to John's help.

John, I started to do some benchmarking, but am getting errors I can't figure out why in Scriptbasic being a noob to the language.

It is based on code here:http://onlyjob.blogspot.com/2011/03/perl5-python-ruby-php-c-c-lua-tcl.html

The benchmark as written takes too much time, so I modified it to stop after 2 results.
Here is the python script that I tested on my gaming notebook and on my android tablet.
Code: [Select]
#!/usr/bin/python -u
import re
import time
import sys

str='abcdefgh'+'efghefgh'
imax=1024/len(str)*1024*4   # 4mb

starttime=time.time();
print "exec.tm.sec\tstr.length"

gstr=''
i=0
twice = 0
while (i < imax+1000):
        i=i+1
        gstr+=str
        gstr=re.sub('efgh','____',gstr)
        lngth=len(str)*i
        if(lngth % (1024*256) == 0):
                print int(time.time()-starttime),"sec\t\t",(lngth/1024),"kb"
twice+=1
if(twice == 2): break # don't want to wait for the whole test

print "\nFinished"

Here is as far as I could get in SB port:
Code: [Select]
s ="abcdefgh"+"efghefgh"
imax = 1024 / LEN(s) * 1024 * 4

starttime = NOW
PRINT "exec.tm.sec\tstr.length"

gstr=""
i=0
c = 0
WHILE ( i < imax + 1000 )
        i=i+1
        gstr+=s
        gstr=REPLACE(gstr,'efgh','____')
        lngth=LEN(s)*i
        IF(lngth % (1024*256) = 0) THEN
                PRINT INT(NOW -starttime),"sec\t\t",(lngth/1024),"kb"
c+=1
IF c= 2 THEN GOTO finito' don't want to wait for the whole test
        END IF
WEND

finito:
PRINT "\nFinished"

Results of the python tests:
Gaming Notebook Python 2.6:
exec.tm.sec     str.length
3 sec           256 kb
15 sec          512 kb

Android Tablet sl4a Python:
exec.tm.sec     str.length
36 sec           256 kb
157 sec          512 kb
« Last Edit: May 20, 2012, 08:37:14 PM by kryton9 »

support

  • Administrator
  • *****
  • Posts: 859
    • Script BASIC Open Source Project
Re: ScriptBasic for Android
« Reply #33 on: May 20, 2012, 11:46:29 AM »
Don't forget to use & not + for string concatenation. It seems that imax is some kind of reserve keyword. SB doesn't support single quote for declaring strings.

Code: [Select]
s ="abcdefgh" & "efghefgh"
i_max =  1024 / LEN(s) * 1024 * 4

starttime = NOW
PRINT "exec.tm.sec\tstr.length\n"

gstr=""
i=0
c = 0
WHILE ( i < i_max + 1000 )
        i=i+1
        gstr&=s
        gstr=REPLACE(gstr,"efgh","____")
        lngth=LEN(s)*i
        IF(lngth % (1024*256) = 0) THEN
                PRINT INT(NOW -starttime)," sec\t\t",(lngth/1024)," KB\n"
c+=1
IF c= 2 THEN GOTO finito
        END IF
WEND

finito:
PRINT "\nFinished\n"

jrs@laptop:~/sb/test$ scriba kentbench.sb
exec.tm.sec   str.length
107 sec      256 KB
436 sec      512 KB

Finished
jrs@laptop:~/sb/test$

Please check the code to make sure the SB version is doing the same as the other languages.

Python test on my laptop:

jrs@laptop:~/sb/bench$ python pstr.py
exec.tm.sec   str.length
9 sec      256 kb
50 sec      512 kb

Finished
jrs@laptop:~/sb/bench$

I wonder how this would run under BaCon?
« Last Edit: May 20, 2012, 04:46:29 PM by support »
Script BASIC Project Manager

kryton9

  • Guest
Re: ScriptBasic for Android
« Reply #34 on: May 20, 2012, 08:32:54 PM »
Thanks John for finding the problems in the test script and making a nice working script.

Here are my results:

Gaming Notebook scriba bm.sb
exec.tm.sec     str.length
27 sec           256 KB
107 sec         512 KB

Gaming Notebook Python 2.6:
exec.tm.sec     str.length
3 sec            256 kb
15 sec          512 kb

Android Tablet scriba bm.sb
281 sec        256 KB
1148 sec        512 KB

Android Tablet sl4a Python:
exec.tm.sec     str.length
36 sec           256 kb
157 sec          512 kb

support

  • Administrator
  • *****
  • Posts: 859
    • Script BASIC Open Source Project
Re: ScriptBasic for Android
« Reply #35 on: May 20, 2012, 09:47:28 PM »
I solved the problem with REPLACE and happy with the results.

Quote
Test code grows text string by adding another string in cycle until it grows up to 4 mb. Each iteration substitutes some text. Every time string becomes 256 KiB larger program prints number of seconds passed since beginning of test.


Code: [Select]
s ="abcdefghefghefgh"
i_max =  1024 / LEN(s) * 1024 * 4

starttime = NOW
PRINT "exec.tm.sec\tstr.length\n"

gstr=""
i=0
c = 0
WHILE ( i < i_max + 1000 )
  i=i+1
  gstr&=s
  lngth=LEN(s)*i
  gstr=REPLACE(gstr,"efgh","____",undef,lngth-16)
  IF(lngth % (1024*256) = 0) THEN
    PRINT INT(NOW -starttime)," sec\t\t",(lngth/1024)," KB\n"
    c+=1
    IF c= 2 THEN GOTO finito
  END IF
WEND

finito:
PRINT "\nFinished\n"

jrs@laptop:~/sb/test$ scriba kentbench.sb
exec.tm.sec   str.length
5 sec      256 KB
34 sec      512 KB

Finished
jrs@laptop:~/sb/test$

Code: [Select]
abcd____________

abcd____________abcd____________

abcd____________abcd____________abcd____________

abcd____________abcd____________abcd____________abcd____________

I compiled the C version for a reference base. (1st MB)

jrs@laptop:~/sb/bench$ ./cstr
exec.tm.sec   str.length
2sec      256kb
6sec      512kb
17sec      768kb
34sec      1024kb
^C
jrs@laptop:~/sb/bench$
« Last Edit: May 21, 2012, 12:07:15 AM by support »
Script BASIC Project Manager

kryton9

  • Guest
Re: ScriptBasic for Android
« Reply #36 on: May 21, 2012, 12:54:53 PM »
Nice updates John. The author of the benchmarks wrote that he wasn't going for optimization's and trying to keep the code uniform across all languages. But it is interesting to see how you did your improvements.
I did the java test on the notebook. It runs through eclipse, but not stand alone.
notebook:
exec.tm.sec   str.length
8sec      256kb
34sec      512kb

To run you need to unzip the attachment into your eclipse workspace folder and open it from the project menu in eclipse and then run.

support

  • Administrator
  • *****
  • Posts: 859
    • Script BASIC Open Source Project
Re: ScriptBasic for Android
« Reply #37 on: May 21, 2012, 05:23:13 PM »
Kent,

I don't have Eclipse installed and don't want to trash my development system with installing Java and all the other dependencies that go with it. I'll take your word on the results and factor the numbers based on your Python run on your gaming netbook.

John
Script BASIC Project Manager

kryton9

  • Guest
Re: ScriptBasic for Android
« Reply #38 on: May 21, 2012, 05:43:16 PM »
I understand John, in fact it is so screwy now with Java. You have Java and OpenJava, there is version 6 the stable release and 7 which has quirks. I never cared for Eclipse, too me it is buggy compared to other IDE's I use. I just installed it to tinker with Android and what you are doing with SB and Android. I personally am not happy with Android, it is not what I expected. For a phone it is fine, but for a true cross platform OS, it doesn't have the right foundation in my book.

I just look at my tablet as a media source at bedtime anymore. It is not the development toy I thought it was going to be.

support

  • Administrator
  • *****
  • Posts: 859
    • Script BASIC Open Source Project
Re: ScriptBasic for Android
« Reply #39 on: May 21, 2012, 06:07:21 PM »
Quote
I just look at my tablet as a media source at bedtime anymore. It is not the development toy I thought it was going to be.

Don't give up so soon. You haven't even played with the GUI yet. (fullscreen, controls, events, ...) The SQLite3 Facade is coming from what I have been told. I plan to use SB Android on a pad with an open source medical practice package as the input device.

Check out the Android Framework PDF I attached.
« Last Edit: May 21, 2012, 08:45:04 PM by support »
Script BASIC Project Manager

support

  • Administrator
  • *****
  • Posts: 859
    • Script BASIC Open Source Project
Re: ScriptBasic for Android
« Reply #40 on: May 22, 2012, 11:16:05 AM »
I was checking into Android emulators that support tablet size screens and physical controls. I was happy to learn that I could create an AVD  and specify device characteristics.

I found this in the Android Developer Guide that might help with GUI layout and design strategies.
Script BASIC Project Manager

kryton9

  • Guest
Re: ScriptBasic for Android
« Reply #41 on: May 22, 2012, 12:23:47 PM »
Thanks for the links John. My interest as you might know currently is in game development and possible future work with robotics, the pc is still the platform for me.

I do like my tablet for reading, surfing and watching videos while trying to get to sleep :)

support

  • Administrator
  • *****
  • Posts: 859
    • Script BASIC Open Source Project
Re: ScriptBasic for Android
« Reply #42 on: May 22, 2012, 12:33:54 PM »
I want to thank you for being one of the first to join in on the bleeding edge of Android (remote) scripting. I think ScriptBasic has an advantage due to it's small footprint and ease of use. Allowing weekend programmers to script their devices to their needs from anywhere is bound to attract attention. It's still early and the DVM extension module in it's infancy. It would be great to see the ScriptBasic project grow with users and developers.

BTW

The SB dev team has two directions going with the ARM version of ScriptBasic. Steve is working on a native ARM compile of SB while Armando is using the Android NDK. Steve has isolated the looping FUNCTION/SUB issue to an assembler bug in the toolchain.
Script BASIC Project Manager

support

  • Administrator
  • *****
  • Posts: 859
    • Script BASIC Open Source Project
Re: ScriptBasic for Android
« Reply #43 on: May 23, 2012, 11:16:10 AM »
Quote
My interest as you might know currently is in game development and possible future work with robotics, the pc is still the platform for me.





iGuess you only have one Apple left in the basket.  :(
Script BASIC Project Manager

kryton9

  • Guest
Re: ScriptBasic for Android
« Reply #44 on: May 24, 2012, 08:22:45 PM »
Cool screenshot John.

Android gained market share as symbian and blackberry lost some.
http://www.bgr.com/2012/05/24/android-ios-market-share-q1-2012-blackberry-idc/

Arm is soon going to be in the new Arduino, already is in the beaglebone and soon to be available rasberry pi. Everything is changing at such a pace!
http://www.wired.com/gadgetlab/2011/09/arduino-arm-products/

Your developers at scriptbasic are set for the future. I will still be testing stuff that you come up with. It was lots of fun going through what we did the last few weeks.