Both products are very fast with comparable performance.
Back in 2014 Tony Roberts, the creator of PyXLL, wrote a blog post comparing the performance of PyXLL and xlwings - https://www.pyxll.com/blog/performance-comparison/. PyXLL was found to be much faster, mainly due to PyXLL targeting the Excel C API directly whereas xlwings used a combination of COM and VBA.
xlSlim targets the Excel C API directly just the same as PyXLL, so I was curious to see if xlSlim’s performance was similar to PyXLL’s. I was very aware that PyXLL is a mature product with 15 years of investment behind it while xlSlim was only recently released.
I started by following the same methodology as the PyXLL blog. I downloaded the spreadsheet and code used from the link https://www.pyxll.com/blog/wp-content/uploads/2014/11/perftest.zip
I slightly updated the PyXLL test code to use the new time.perf_counter() method:
I created equivalent code for xlSlim, substituting type hints for the PyXLL decorators:
I then used the techniques described on the PyXLL blog to time how long Excel takes to make many tiny function calls using PyXLL and xlSlim. In the original test PyXLL was between 300 to 1000 times faster than xlwings, so I was hoping to do better than that.
The results were very encouraging. Firstly, I had to change the time scale to milliseconds which is a good start! xlSlim was 1 to 2 times slower than PyXLL, however both solutions are blazingly fast with both being capable of 100k functions calls in under a second.
The next test in the original PyXLL blog was passing large ranges of data from Excel to Python, so passing ranges of 1000, 2000, 5000…. cells and so on. Here the results showed that xlSlim was up to 8 times faster when passing 10 million cells into a function, taking only 134 milliseconds!
These results were curious so I did some research. I found that on https://www.pyxll.com/docs/userguide/udfs/numpy.html Tony wrote “Floating point numpy arrays are the fastest way to get data out of Excel into Python”. Fair enough, I too optimized for numpy arrays. My next task was to add a test for passing large numpy arrays to functions.
I added this function for PyXLL:
And this function for xlSlim:
I retested with these new functions that transform Excel ranges into numpy arrays before calling Python code. I found PyXLL to be a little faster than xlSlim, with the difference dropping to 1.29 times when creating a numpy array with 10 million elements. Again, both solutions are blazingly fast, creating a 10 million element numpy array in under 200 milliseconds.
In summary, both PyXLL and xlSlim are very fast. I cannot see a rationale for choosing one product over the other based on performance considerations. I was happy to see xlSlim v1.0 doing so well when compared to a mature product like PyXLL.
1 comment
Really helpful. Thank you