Just finished running some benchmarks on my Nim tensor code vs Python and NumPy. Honestly wasn't expecting results this good but here we are.
Quick background: I'm doing my masters in cybersecurity but fell down a rabbit hole with Nim for AI stuff. Everyone keeps saying Python is the only realistic option for AI work, so I figured I'd actually test that claim instead of just accepting it.
What I benchmarked:
Results that actually surprised me:
Nim vs Pure Python:
Nim vs NumPy:
Why this matters:
Look, I'm not claiming Nim is going to dethrone NumPy anytime soon. But these numbers show that maybe we don't have to just accept Python's problems as "the cost of doing AI." The performance gap isn't this massive wall everyone makes it out to be.
Planning to keep building this out and see how far it goes. Anyone else getting tired of fighting with Python environments and want to try something different?
Raw benchmark data (all times in milliseconds):
{
"nim": {
"creation_50x50": 105.0,
"creation_100x100": 214.0,
"creation_200x200": 159.0,
"addition_50x50": 7.0,
"addition_100x100": 13.0,
"addition_200x200": 9.0,
"matmul_25x25": 2.0,
"matmul_50x50": 14.0,
"matmul_100x100": 13.0,
"elementwise_50x50": 13.0,
"elementwise_100x100": 20.0,
"elementwise_200x200": 13.0
},
"python": {
"creation_50x50": 961.6,
"addition_50x50": 247.2,
"elementwise_50x50": 409.7,
"creation_100x100": 1922.3,
"addition_100x100": 428.9,
"elementwise_100x100": 728.0,
"creation_200x200": 1524.9,
"addition_200x200": 362.0,
"elementwise_200x200": 556.1,
"matmul_25x25": 113.7,
"matmul_50x50": 817.8,
"matmul_100x100": 681.8
},
"numpy": {
"creation_50x50": 35.2,
"addition_50x50": 0.9,
"elementwise_50x50": 2.2,
"creation_100x100": 66.6,
"addition_100x100": 1.2,
"elementwise_100x100": 2.3,
"creation_200x200": 52.4,
"addition_200x200": 0.8,
"elementwise_200x200": 1.3,
"matmul_25x25": 0.2,
"matmul_50x50": 0.6,
"matmul_100x100": 2.8
}
}
You can reach Numpy speed and even beat it if you use optimised Nim code (which isn't impossible to tell here since you'r how any code).
In my experience, Arraymancer is as fast or faster than Numpy in most cases.