Python & ADO 2.6 load time (early binding, late binding) 
Author Message
 Python & ADO 2.6 load time (early binding, late binding)

Hi python-gurus,

I would like to use python as a server-side language, for building
dynamic business-objects that access a MS SQL Server 2000 database.

I do not care about cross-platform compatibility, so I would like to
use ADO for accessing the database.

I have made some test scripts that fetch some data in a table, and
print the result, with both early-binding and late-binding. I have
noticed that the ADO module load time is quite high:

Late-binding:  0.3 seconds
Early-binding: 0.4 seconds

On the opposite, accessing the same data with the module included in
the Python 2.0 distribution is really quick. The whole script completes
in 0.1 seconds, "select * from..." included. And with a stored
procedure, you can imagine this is even faster.

I wonder if there is a way to avoid loading the ADO module each time a
python script is launched. Is there a way to run a python environment
in background (Windows service?), and then just call the "living"
objects, without having to recreate them each time?

Thanks

--
Philippe Lang

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Mon, 19 May 2003 03:00:00 GMT  
 Python & ADO 2.6 load time (early binding, late binding)

Quote:

> Hi python-gurus,

> I would like to use Python as a server-side language, for building
> dynamic business-objects that access a MS SQL Server 2000 database.

> I do not care about cross-platform compatibility, so I would like to
> use ADO for accessing the database.

> I have made some test scripts that fetch some data in a table, and
> print the result, with both early-binding and late-binding. I have
> noticed that the ADO module load time is quite high:

> Late-binding:  0.3 seconds
> Early-binding: 0.4 seconds

> On the opposite, accessing the same data with the module included in
> the Python 2.0 distribution is really quick. The whole script completes
> in 0.1 seconds, "select * from..." included. And with a stored
> procedure, you can imagine this is even faster.

If you are embedding Python in your code, then you should work just like
Python itself - you take the hist first time, but after that everything
is fast.  There is no need to take that hit each call.

Unfortunately, you didnt show any code, so I have no idea how you are
trying to do all this...

Mark.



Mon, 19 May 2003 03:00:00 GMT  
 Python & ADO 2.6 load time (early binding, late binding)


Quote:
> If you are embedding Python in your code, then you should work just
> like Python itself - you take the hist first time, but after
> that everything is fast.  There is no need to take that hit each
> call.

> Unfortunately, you didnt show any code, so I have no idea how you are
> trying to do all this...

Hi Mark,

Here is the code...

-----------------------------------------------------------------------
 module.py:
-----------------------------------------------------------------------

import time

def test():
    # Time
    t = time.time()
    old_t = t
    print t - old_t

    # Late Binding...
    # import win32com.client.dynamic
    # adoConn = win32com.client.dynamic.Dispatch('ADODB.Connection')

    # ...or early Binding
    import win32com.client
    adoConn = win32com.client.Dispatch('ADODB.Connection')

    # Time
    old_t = t
    t = time.time()
    print t - old_t

    # ADO Query
    adoConn.Open('pythontest')
    (adoRS, success) = adoConn.Execute('select * from tblTest')
    adoRS.MoveFirst()
    print "---> article = ", adoRS.Fields("article")
    print "---> quant = ",adoRS.Fields("quant")

    # Time
    old_t = t
    t = time.time()
    print t - old_t

    # Print ADO Binding
    print `adoConn`

-----------------------------------------------------------------------
 module_test.py:
-----------------------------------------------------------------------

import module

module.test()

-----------------------------------------------------------------------

... and here are the tests. I delete module.pyc, an then run the script
three times. As you can see, there is no performance improvement the
second or third time the script is run. ADO Load time is always around
0.4 seconds.

C:\>del module.pyc

C:\>python test_module.py
0.0
0.411000013351
---> article =  a
---> quant =  1
0.200000047684
<win32com.gen_py.Microsoft ActiveX Data Objects 2.6 Library._Connection>

C:\>python test_module.py
0.0
0.381000041962
---> article =  a
---> quant =  1
0.179999947548
<win32com.gen_py.Microsoft ActiveX Data Objects 2.6 Library._Connection>

C:\>python test_module.py
0.0
0.391000032425
---> article =  a
---> quant =  1
0.189999938011
<win32com.gen_py.Microsoft ActiveX Data Objects 2.6 Library._Connection>

-----------------------------------------------------------------------

And here are the results with late binding:
-------------------------------------------

C:\>del module.pyc

C:\>python test_module.py
0.0
0.330999970436
---> article =  a
---> quant =  1
0.310000061989
<COMObject ADODB.Connection>

C:\>python test_module.py
0.0
0.299999952316
---> article =  a
---> quant =  1
0.200999975204
<COMObject ADODB.Connection>

C:\>python test_module.py
0.0
0.310000061989
---> article =  a
---> quant =  1
0.190999984741
<COMObject ADODB.Connection>

-----------------------------------------------------------------------

Because of this 0.4 seconds hit each time ADO is loaded, I wondered if
it was possible to put "live" objects into some kind of "Python
server", and call them when needed?

Thanks for your time.

--
Philippe Lang

Sent via Deja.com http://www.deja.com/
Before you buy.



Tue, 20 May 2003 03:00:00 GMT  
 Python & ADO 2.6 load time (early binding, late binding)

Quote:



>> If you are embedding Python in your code, then you should work just
>> like Python itself - you take the hist first time, but after
>> that everything is fast.  There is no need to take that hit each
>> call.

>> Unfortunately, you didnt show any code, so I have no idea how you are
>> trying to do all this...

> Hi Mark,

> Here is the code...

You are demonstrating that creating an ADO connection takes time.  This
shouldnt come as a surprise.  The late and early binding will have
almost no effect here.

In a "real" program, you would be likely to open the connection once,
and share it for all database work.  There is no facility to have a
"remote server" of Python objects - that is the job of _your_ process
and Python variables - just keep the object alive in _your_ process.
Don't call a new "python.exe" for each database operation.

Mark.



Wed, 21 May 2003 08:34:31 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. python com, early and late binding problem

2. J 3.2 - Early vs. Late Verb Bindings

3. how do i bind an msflexgrid to an ado recordset

4. Python & wxPython on Solaris 2.6

5. ADO binding

6. Can most objects be early bound?

7. win32com and early binding: Definitive answer?

8. Python bindings for Qt & KDE

9. Late Binding

10. Late Binding?

11. Late binding in VO, please HELP!!!

12. Late-binding Performance (long)

 

 
Powered by phpBB® Forum Software