[issue40314] python code order of magnitude faster than equivalent CPython code for simple import statement

2020-04-21 Thread deekay


deekay  added the comment:

The times are correct. It's very noticeable even without using a stopwatch. The 
C version actually takes 23 seconds to execute.

--

___
Python tracker 
<https://bugs.python.org/issue40314>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40314] python code order of magnitude faster than equivalent CPython code for simple import statement

2020-04-17 Thread deekay


New submission from deekay :

I'm baffled by the performance difference of the following two semantically 
equivalent(?) programs.

Python:

#test.py
import time
starttime=time.time()
import tensorflow 
print(f"Import took: {time.time() - starttime}")

vs C using CPython

//test.c
#include 
#include  
#include  
int main(int argc, char *argv[])
{
Py_Initialize();
clock_t t = clock();
PyObject* pModule = PyImport_ImportModule("tensorflow");
double time_taken = ((double)clock() - t)/CLOCKS_PER_SEC;
printf("Import took:  %f\n", time_taken);
return 0;
}

Now compare the two:

cl.exe /I"C:\Program Files\Python37\include" test.c
link test.obj python37.lib /LIBPATH:"C:\Program Files\Python37\libs"
.\test.exe


> 2020-04-17 13:00:51.598550: W 
> tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load 
> dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
> 2020-04-17 13:00:51.606296: I 
> tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart 
> dlerror if you do not have a GPU set up on your machine.

> **Import took: 23.160523891448975**


python test.py


> 2020-04-17 13:01:19.525648: W 
> tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load 
> dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
> 2020-04-17 13:01:19.530726: I 
> tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart 
> dlerror if you do not have a GPU set up on your machine.

> **Import took: 2.3172824382781982**


Not that it should matter much but my tensorflow version is 1.15
Why is the python VM code so much faster than the compiled CPython code?
Does the python vm add some magic that PyImport_ImportModule doesn't?

--
components: C API
messages: 366683
nosy: deekay
priority: normal
severity: normal
status: open
title: python code order of magnitude faster than equivalent CPython code for 
simple import statement
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue40314>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40312] Weakref callbacks running before finalizers in GC collection

2020-04-17 Thread deekay


deekay  added the comment:

Wrong thread, wrong thread, abort!
Sorry, I meant to submit this as a separate issue.
I don't see a delete option.
Maybe a mod can remove this please?

--

___
Python tracker 
<https://bugs.python.org/issue40312>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40312] Weakref callbacks running before finalizers in GC collection

2020-04-17 Thread deekay


deekay  added the comment:

I'm baffled by the performance difference of the following two semantically 
equivalent(?) programs.

Python:

#test.py
import time
starttime=time.time()
import tensorflow 
print(f"Import took: {time.time() - starttime}")

C using CPython

//test.c
#include 
#include  
#include  
int main(int argc, char *argv[])
{
Py_Initialize();
clock_t t = clock();
PyObject* pModule = PyImport_ImportModule("tensorflow");
double time_taken = ((double)clock() - t)/CLOCKS_PER_SEC;
printf("Import took:  %f\n", time_taken);
return 0;
}

Now compare the two:


cl.exe /I"C:\Program Files\Python37\include" test.c
link test.obj python37.lib /LIBPATH:"C:\Program Files\Python37\libs"
.\test.exe


> 2020-04-17 13:00:51.598550: W 
> tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load 
> dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
> 2020-04-17 13:00:51.606296: I 
> tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart 
> dlerror if you do not have a GPU set up on your machine.

> **Import took: 23.160523891448975**


python test.py


> 2020-04-17 13:01:19.525648: W 
> tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load 
> dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
> 2020-04-17 13:01:19.530726: I 
> tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart 
> dlerror if you do not have a GPU set up on your machine.

> **Import took: 2.3172824382781982**


Not that it should matter much but my tensorflow version is 1.15
Why is the python VM code so much faster than the compiled CPython code?
Does the python vm add some magic that PyImport_ImportModule doesn't?

--
nosy: +deekay

___
Python tracker 
<https://bugs.python.org/issue40312>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com