ScriptBasic extension modules seem to compile fine native and half the size as the NDK counterpart.
declare sub MD5 alias "md5fun" lib "t"
m = MD5("JRS")
for x = 1 to len(m)
print right("0" & hex(asc(mid(m,x,1))),2)
next
printnl
shell@android:/sdcard/scriptbasic $ scriba t_md5.sb
95B75AF8A9A72665C52E361994020219
shell@android:/sdcard/scriptbasic $ ls -l /data/data/org.connectbot/bin/ScriptBasic/lib
-rwxr-xr-x u0_a119 u0_a119 7736 2013-08-04 22:10 t.so
-rwxr-xr-x u0_a119 u0_a119 14161 2013-08-01 18:49 t_ndk.so
shell@android:/sdcard/scriptbasic $
This is a SB
MD5 example running on Android compared to the Linux C version. The SB version has to do the following.
- Load scriba
- Parse/tokenize script
- Load extension module and declare external functions
- Load 4.3 MB string from a file into a SB string variable
- Call the extension module MD5 function passing the loaded text of the bible.
- Format binary results to a HEX string
- Cleanup memory, unload extension module and exit scriba
Compare that to a compile C program that is a standard Linux utility and there is 3 tenths of a second difference. 8)
declare sub MD5 alias "md5fun" lib "t"
declare sub LoadString alias "loadstring" lib "t"
s = LoadString("Bible.txt")
m = MD5(s)
for x = 1 to len(m)
print right("0" & hex(asc(mid(m,x,1))),2)
next
printnl
shell@android:/sdcard/scriptbasic $ time scriba md5cc.sb
17CE80BA9F6A0F74093C575205C9CB17
0m0.12s real 0m0.06s user 0m0.04s system
shell@android:/sdcard/scriptbasic $ time md5 Bible.txt
17ce80ba9f6a0f74093c575205c9cb17 Bible.txt
0m0.09s real 0m0.05s user 0m0.02s system
shell@android:/sdcard/scriptbasic $
shell@android:/sdcard/scriptbasic $ ls -l Bible.txt
-rw-rw-r-- root sdcard_rw 4397206 2012-07-01 00:45 Bible.txt
shell@android:/sdcard/scriptbasic $