[Gambas-user] Gambas is slower than Python??
Dominique SIMONART
simonart.dominique at ...11...
Sun Jan 18 05:43:42 CET 2009
birchy a écrit :
> I'm quite confused. I'm from a VB6 background, so when i moved to Ubuntu as
> my main O.S. Gambas was very attractive. Several things (mainly poor
> documentation) pushed me to try other languages. Having done a little C,
> C++, Java and PHP, i decided to give Python a go as it's getting very
> popular. I ported a function that i have used for many years in VB6 into
> Gambas and (today) have ported it to Python. Results are quite shocking to
> be honest. The following code takes 4.2sec to run on my oldish AMD 3000 pc.
> The Python version takes 1.9sec. Pythn is "only" a scripting language, so
> what gives??
>
> PUBLIC SUB Main()
> DIM i AS Integer, t AS Float, s AS String
>
> t = Timer
> FOR i = 0 TO 999999
> s = GetSubstring("QWERTYUIOP", "WE", "IO")
> NEXT
> PRINT Timer - t
> END
>
> PRIVATE FUNCTION GetSubstring(doc AS String, startstring AS String,
> endstring AS String) AS String
> RETURN Split(Split(doc, startstring)[2], endstring)[0]
> END
>
>
I was curious about the test, so I ran it on my PC and got 4.66 sec
I also tried some modifications like the one below ( 2.49 sec) using the
String classe, wich is the correct way to process strings in Gambas
But if I remove all the "String." prefixes and the test instructions, I
get 1.27 sec!
Spliting is easy, but it has a cost...and if you replace the "ER" string
by "AB" your prog abort with an "out of bound" message ;-)
PRIVATE FUNCTION GetSubstring(doc AS String, startstring AS String,
endstring AS String) AS String
DIM i, j AS Integer
i = String.InStr(doc, startstring) + String.Len(startstring)
IF i = 0 THEN RETURN "" ' or i = 1 it's a choice
j = InStr(doc, endstring, i)
IF j = 0 THEN RETURN "" ' or j = len(doc)
RETURN String.Mid(doc, i, j - i)
END
PUBLIC SUB Button1_Click()
DIM i AS Integer, t AS Float, s, m, n, p AS String
m = "QWERTYUIOP"
n = "WE"
p = "IO"
t = Timer
FOR i = 0 TO 999999
s = GetSubstring(m, n, p)
NEXT
Label1.Caption = CString(Timer - t)
END
regards,
Dominique Simonart
More information about the User
mailing list