|
From: | tyler |
Subject: | Re: [Openexr-devel] Speeding up Python |
Date: | Mon, 1 Apr 2019 14:12:23 -0700 |
The native imath python arrays are pretty fast, I think your version is triggering an element by element python copy of data into the numpy array. Here's the timings with the native (fast) array copy and the python only iteration on the array types. Here's the script:import imathimport timecount = 1000000ai = imath.V3dArray(imath.V3d(0.25, 0.3, 0.75), count)ao = imath.V3dArray(count)start = time.time()ao[:] = aiend = time.time()print 'Copying %d elements: %0.06f seconds' % (count, end-start)start = time.time()for i in range(count):ao[i] = ai[i]end = time.time()print 'Python iteration %d elements: %0.06f seconds' % (count, end-start)And the output:> python2 foo.pyCopying 1000000 elements: 0.003245 secondsPython iteration 1000000 elements: 0.994242 secondsDoes that match what you're seeing? That's also without enabling the multithreading that's built into the array operations.-nickOn Mon, Apr 1, 2019 at 12:46 PM Tyler Fox <address@hidden> wrote:_______________________________________________Getting data in and out of imath in python is *SLOW*. And yes, Python is a slow language, but that doesn't mean we can't kick it up a notch.Could I get some feedback on my proposals to speed things up?https://github.com/openexr/openexr/pull/373First is a PR with a *very* simple change that just exposes the memory address of the imath object.With a few lines of python code, you can read the c-data and re-interpret it in whatever way you want.This is an issue where I described a more complex (and maybe more pythonic?) way of exposing the underlying data.Either of these proposals could remove the need for imathnumpy... Or imathnumpy could be replaced with a pure-python module that handles the more error prone memory mapping.Thoughts?~T.Fox
Openexr-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/openexr-devel
[Prev in Thread] | Current Thread | [Next in Thread] |