Open Forum > What's New
ScriptBasic for Android
kryton9:
Glad you got it working under Linux.
Support:
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.
--- End quote ---
kryton9:
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: ---#!/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"
--- End code ---
Here is as far as I could get in SB port:
--- Code: ---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"
--- End code ---
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
Support:
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: ---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"
--- End code ---
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?
kryton9:
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
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version