[Gambas-user] Gambas is slower than Python??

Benoit Minisini gambas at ...1...
Sun Jan 18 18:44:59 CET 2009


On dimanche 18 janvier 2009, birchy wrote:
> Benoit Minisini wrote:
> > Can you show us the code in Python? Maybe it will help me to find
> > something
> > that could be enhanced in Gambas if Python can do better? :-)
>
> Ok, i think the bottleneck is related to the function call overhead:
>
> PYTHON: wrote:
> > import time
> >
> > t = time.time()
> > for i in range(999999):
> >     s = "QWERTYUIOP".partition("WE")[2].partition("IO")[0]
> > print time.time() - t
>
> GAMBAS: wrote:
> > PUBLIC SUB Main()
> >   DIM i AS Integer, t AS Float, s AS String
> >
> >   t = Timer
> >   FOR i = 0 TO 999999
> >     s = Scan("QWERTYUIOP", "*WE*IO*")[1]
> >   NEXT
> >   PRINT Timer - t
> > END
>
> Both of these run significantly faster when put in-line but Python is still
> ~33% faster. Perhaps you could add a new string function to achieve this as
> it is VERY useful, yet rarely (if ever) seen in other languages?

For sure, Scan() is far slower than this partition() built-in function, as 
partition only searches for one string and returns what was found before, the 
searched string, and what was found after.

As I never used Python, I don't really realized how much an equivalent of 
partition() is needed.

But if Scan() is slower than partition(), it does not mean necessarily that 
Python is faster than Gambas globally. For example, just iterating a void 
loop 0..999999 takes 0,1s in Python, and 0,029s in Gambas 3.

If you want, I could make a partition() function temporarily just to compare 
exactly the same thing between Gambas and Python. Do you?

-- 
Benoit Minisini




More information about the User mailing list