RosettaCode

(Topics Related to FBSL)

Re: RosettaCode

Unread postby Mike Lobanovsky » Tue May 07, 2013 10:51 am

He-he, :)

Qt is a wonderful "cutie". It's primarily a beautiful platform-independent windowing framework that provides the basis for GUI solutions to a lot of platforms that lack what Windows offers on default. wxWidgets and GTK are stone age axes as compared to Qt. I used commercially licensed Qt in my freelance jobs and I must admit I don't know any other set of GUI RAD tools that can compare to what that package offers for free to GNU GPL partisans, which I am not.

Believe it or not, the other list of libraries is what other languages use just to get themselves up and running. Almost all of them are part of their respective distribution packages thus fitting into the reservation I mentioned earlier perfectly. The list of RosettaCode contestants is quite long hence the seemingly spacious list of usable libraries. FBSL could use some of them which are not so outrageously language-specific but still it'd be contrary to the common rules.
Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus

Re: RosettaCode

Unread postby bugmagnet » Thu May 09, 2013 6:15 pm

Mike

Work has caught up with me. That and a few late nights / early mornings debugging code and climbing the SQLServer2012 learning curve.

I have submitted some of our code to RC.

The next question I have is, which is faster in the dec2bin code below, to use BAND and >> or to use MOD and \

Kind regards,
Bruce.
Code: Select all
#APPTYPE CONSOLE

FUNCTION dec2bin(n AS INTEGER) AS STRING
    DIM num AS INTEGER = n
    DIM res AS STRING = ""
    IF num = 0 THEN RETURN "0"
    DO
        IF num = 0 THEN EXIT DO
        'res = num MOD 2 & res
        res = (num BAND 1) & res
        'num = num \ 2
        num = num >> 1
    LOOP
    RETURN res
END FUNCTION

FOR DIM i = 0 TO 32767
    PRINT dec2bin(i), CR;
NEXT
PAUSE


User avatar
bugmagnet
FBSL geek
FBSL geek
 
Posts: 175
Joined: Sat Apr 06, 2013 5:58 am
Location: Fremantle WA, Australia

Re: RosettaCode

Unread postby Codeman » Thu May 09, 2013 7:04 pm

BAND and >> must be faster in front of division because they are basic binary instruction and mov in asm equivalent where the division use slower instruction i think.
if mike can confirm i am pretty sure i will be right, also as it is an assumption you can test the speed using big loops and gettickcount as references

edit: seems i was wrong: here is the test code with gettickcount that show that the mod + / is faster lol

Code: Select all
#APPTYPE CONSOLE

FUNCTION dec2bin(n AS INTEGER) AS STRING
    DIM num AS INTEGER = n
    DIM res AS STRING = ""
    IF num = 0 THEN RETURN "0"
    DO
        IF num = 0 THEN EXIT DO
        'res = num MOD 2 & res
        res = (num BAND 1) & res
        'num = num \ 2
        num = num >> 1
    LOOP
    RETURN res
END FUNCTION

FUNCTION dec2bina(n AS INTEGER) AS STRING
    DIM num AS INTEGER = n
    DIM res AS STRING = ""
    IF num = 0 THEN RETURN "0"
    DO
        IF num = 0 THEN EXIT DO
       res = num MOD 2 & res
        'res = (num BAND 1) & res
        num = num \ 2
       'num = num >> 1
    LOOP
    RETURN res
END FUNCTION

DIM gtc AS INTEGER

gtc = GetTickCount()
FOR DIM i = 0 TO 32767
     dec2bin(i)
NEXT
? ": ",GetTickCount() - gtc, " milliseconds"

gtc = GetTickCount()
FOR DIM i = 0 TO 32767
     dec2bina(i)
NEXT
?  ": ",GetTickCount() - gtc, " milliseconds"
PAUSE
_-=<(¯`·._.·[ CodeMan ]·._.·´¯)>=-_
Your only limit : Your imagination

FBSL V3 TESTED On :
Image

Chris 1 (Corei5-4460S 2.9 GHZ w/ 16GB RAM, GeForce GTX 745 w/ 4GB VRAM, Windows 8 x64 Fr)
Chris 2 (2.0GHz AMD Atlon 64 X2 3800+ w/ 4GB RAM, GeForce 9600GT w/ 1GB VRAM, Windows 7 x64 Fr)
Chris 3 (Tablet pc : ASUS Transformer Book T100)
User avatar
Codeman
FBSL Administrator
FBSL Administrator
 
Posts: 497
Joined: Sat Nov 24, 2007 4:33 pm
Location: France

Re: RosettaCode

Unread postby bugmagnet » Thu May 09, 2013 7:16 pm

Codeman wrote:you can test the speed using big loops and gettickcount as references

Which I would do ordinarily. However, at 1:13AM (it's GMT+8 here) after trying to be brilliant with T-SQL (a language I'm not particularly familiar with, nor fond of), I think getting horizontal is more pressing that speed tests.

Kind regards,
Bruce.
User avatar
bugmagnet
FBSL geek
FBSL geek
 
Posts: 175
Joined: Sat Apr 06, 2013 5:58 am
Location: Fremantle WA, Australia

Re: RosettaCode

Unread postby Codeman » Thu May 09, 2013 7:18 pm

edited my previous post on purpose, have a good night :p
_-=<(¯`·._.·[ CodeMan ]·._.·´¯)>=-_
Your only limit : Your imagination

FBSL V3 TESTED On :
Image

Chris 1 (Corei5-4460S 2.9 GHZ w/ 16GB RAM, GeForce GTX 745 w/ 4GB VRAM, Windows 8 x64 Fr)
Chris 2 (2.0GHz AMD Atlon 64 X2 3800+ w/ 4GB RAM, GeForce 9600GT w/ 1GB VRAM, Windows 7 x64 Fr)
Chris 3 (Tablet pc : ASUS Transformer Book T100)
User avatar
Codeman
FBSL Administrator
FBSL Administrator
 
Posts: 497
Joined: Sat Nov 24, 2007 4:33 pm
Location: France

Re: RosettaCode

Unread postby Mike Lobanovsky » Thu May 09, 2013 7:40 pm

@Bruce:

I have more remarks to your code than just what you're asking about. When I'm talking about "server side", I mean what happens in FBSL virtual machine's machine code. When I'm talking about "client side" instructions, I mean extra overhead of reading additional data from your script, like +'s, -'s, relational operators, assignments, casts etc. and of following your instructions. CPU clocks can be seen in the FbslAsm.chm that comes in the initial Beta package.

1. BAND is faster than \. It resolves to a 1-clock AND instruction. \ resolves to a 41-clock integer DIV instruction plus a lot of preparatory trickery to get the registers ready for division.
2. Right shift is faster than MOD. It resolves to a 1-clock SHR instruction. MOD resolves to the remainder of 41-clock DIV instruction plus a lot of preparatory trickery to get the registers ready for division.
3. "Do/Loop" is not the proper choice. It needs extra client-side overhead to evaluate its break condition. "While num" does everything on the server side.
4. When it can, FBSL casts its Variants on the server side automatically -- faster than it follows your enforced "As Integer/As String/etc" client-side instructions. Simple maths and concatenation don't require your interaction. Just let FBSL do it for you automatically whenever possible; it's smart and fast enough for that.
5. Your code will run either way and nobody's gonna know it could have run faster -- but you and me. I was serious when I said that what I suggested for this solution was the fastest code that could be written in pure FBSL. I am glad to see you exploring your own ways but I don't mind your posting my solutions on your own behalf either; I'm not that avid nor am I jealous at all... :D

@Codeman:

No way Chris, no way. The bitshift loops are too short (irrespective of the number of numerals which are always only 32 bits long) to show the real differences against all the overhead that's involved in running the inner loops as such. You have to think twice before you decide what to benchmark and how. On my PC, the results for your "benchmark" are as follows:

NoWay.PNG

When I say "inner", I mean the bitshifting loops proper -- the ones that are within the functions. The For/Next loops that iterate through the numerals and call the functions are usually referred to as "outer".
You do not have the required permissions to view the files attached to this post.
Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus

Re: RosettaCode

Unread postby Codeman » Thu May 09, 2013 7:49 pm

yes mike they appear equal sometime but if you run bigger loops and several times it show that the mod + \ solution is equal or faster than yours, at least on my pc :/
_-=<(¯`·._.·[ CodeMan ]·._.·´¯)>=-_
Your only limit : Your imagination

FBSL V3 TESTED On :
Image

Chris 1 (Corei5-4460S 2.9 GHZ w/ 16GB RAM, GeForce GTX 745 w/ 4GB VRAM, Windows 8 x64 Fr)
Chris 2 (2.0GHz AMD Atlon 64 X2 3800+ w/ 4GB RAM, GeForce 9600GT w/ 1GB VRAM, Windows 7 x64 Fr)
Chris 3 (Tablet pc : ASUS Transformer Book T100)
User avatar
Codeman
FBSL Administrator
FBSL Administrator
 
Posts: 497
Joined: Sat Nov 24, 2007 4:33 pm
Location: France

Re: RosettaCode

Unread postby Mike Lobanovsky » Thu May 09, 2013 8:02 pm

1. FBSL is optimized for Intels when compiled rather than for AMD's. You can't optimize for both.
2. I said, for such short inner bitshift loops as 32 bits, the difference against the loops themselves might not be seen irrespective of how many numerals you test. If you take a long byte string and try to bitshift or divide its contents byte-by-byte as in many data compression algos, you'll see the difference. Much difference. Very much difference.
3. The fluctuations are due to dozens or hundreds of other processes running concurrently on your PC. Accurate benchmarking of such short loops requires high-performance counters and top priority for the benchmarking process.
4. I told Bruce he can use any solution and nobody's gonna notice the difference, but I also presented a ton of proof why what I'm saying might be true.
Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus

Re: RosettaCode

Unread postby Mike Lobanovsky » Thu May 09, 2013 9:22 pm

Bruce wrote:Roko, mat jane do. Roko mat, jane do. So much in that comma.


So? We simply can't wait any longer... :)

Also, why doesn't anybody ask why FBSL's PRINT in
Code: Select all
...
PRINT STRENC(s), " contains ", STRENC("o"), " at the following locations:", InstrEx(s, "o")
...

doesn't bark at the trailing InstrEx() which is in fact a Sub that contains its own PRINT statements? :winkwink:
Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus

Re: RosettaCode

Unread postby bugmagnet » Fri May 10, 2013 6:26 am

Mike Lobanovsky wrote:
Bruce wrote:Roko, mat jane do. Roko mat, jane do. So much in that comma.

So? We simply can't wait any longer... :)

Yes, it was a totally unnecessary addition to that posting. Just because it's interesting to a Hindi or Urdu speaker has little to do with RC task at hand.
Mike Lobanovsky wrote:Also, why doesn't anybody ask why FBSL's PRINT in
Code: Select all
...
PRINT STRENC(s), " contains ", STRENC("o"), " at the following locations:", InstrEx(s, "o")
...

doesn't bark at the trailing InstrEx() which is in fact a Sub that contains its own PRINT statements? :winkwink:

It is a little odd. Another of those Freestyle things? I shall have to pay more attention in future. In fact, I think I shall go and have another look right now!

Kind regards,
Bruce

P.S. 'bark' or 'baulk'?
User avatar
bugmagnet
FBSL geek
FBSL geek
 
Posts: 175
Joined: Sat Apr 06, 2013 5:58 am
Location: Fremantle WA, Australia

Re: RosettaCode

Unread postby Mike Lobanovsky » Fri May 10, 2013 10:35 am

bugmagnet wrote:P.S. 'bark' or 'baulk'?

Hehe, in fact whichever... This one was also posted at almost half past two in the morning. :)

bugmagnet wrote:It is a little odd. Another of those Freestyle things?

Exactly. FBSL is aware of "freestyle" propensities of some of its fans (wink-wink Codeman) and it expects InstrEx() to return some printable value regardless of its being a Sub. This lets the Sub's own PRINT take over and continue printing on the same line. As soon as the Sub returns, the main script's PRINT prints its return value which in this case is an empty string "". FBSL Variants' inner structures are always initialized with zeros in their numeric fields and with empty strings, in their string fields.

This done, the main PRINT finally encounters a CRLF at the end of its own line and sends the caret to the line that follows to print "Press any key to continue...".
Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus

Re: RosettaCode

Unread postby Mike Lobanovsky » Fri May 10, 2013 11:03 pm

Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus

Re: RosettaCode

Unread postby bugmagnet » Sat May 11, 2013 11:56 am

Here's one of mine: Ordered Words
User avatar
bugmagnet
FBSL geek
FBSL geek
 
Posts: 175
Joined: Sat Apr 06, 2013 5:58 am
Location: Fremantle WA, Australia

Re: RosettaCode

Unread postby Mike Lobanovsky » Sat May 11, 2013 1:45 pm

Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus

Re: RosettaCode

Unread postby Mike Lobanovsky » Sat May 11, 2013 2:07 pm

bugmagnet wrote:Here's one of mine: Ordered Words


Nearly perfect! :D

Seems like
Code: Select all
DIM max AS INTEGER = UBOUND(dict)

would be more correct or "theWord = dict[i]" will create an extra empty element in the dynamic dict[] array when i = max = COUNT(dict).

By the way, we have every right to immediately follow F# in the Contents. FBSL's block capitals will keep on moving us up front until someone develops something that starts with "FA". :D
Mike
"Я старый солдат, мадам, и не знаю слов любви."
"I am an old soldier, ma'am, and I don't know the words of love."
"Je suis un vieux soldat, madame, et je ne connais pas les mots d'amour."
"Ich bin ein alter Soldat, gnädige Frau, und ich weiß nicht die Worte der Liebe."

__________________________________________________________________________________________________________________________________________________
(3.2GHz i5 Core Quad, 8GB RAM / 2 x nVidia GTX 550Ti SLI-bridged, 2GB VRAM)
(x86 Win XP Pro Russian Sp3/x86 Win Vista Ultimate Sp2/x64 Win 7 Ultimate Sp1/Wine in x64 elementaryOS Luna)
User avatar
Mike Lobanovsky
FBSL Administrator
FBSL Administrator
 
Posts: 1824
Joined: Tue Apr 19, 2005 8:22 am
Location: Republic of Belarus

PreviousNext

Return to FBSL v3 Discussion Board

Who is online

Users browsing this forum: No registered users and 1 guest

cron