Notifications
Clear all

[Closed] Maxscript vs SDK speed test

I’m trying the SDK for the first time and thought I’d try a very simple function speed test. For those interested, here are the results:

Please correct this code if its not a fair test.

Maxscript:


 gc()
 t1 = timeStamp()
 test = 0.0
 for i = 1 to 5000000 do --however many iterations
 (
 	test += 0.2*0.3
 )
 format "maxscript
result:%
time:% ms
" test (timeStamp() - t1)
 t1 = timeStamp()
 test = fpbasics.products 0.2 0.3
 format "plugin
result:%
time:% ms
" test (timeStamp() - t1)
 

The fpbasics.products function is a slightly tweaked version of the fpbasics sample provided with the SDK. The main function is as follows.


 float FP_Basic::products(float x, float y)
 {
 	float i,k;
 	k = 0;
 	for (int i = 0; i < 5000000; i++)
 	{
 		k += x * y;
 	}
 	return k;
 }
 

Listener output :

OK
maxscript
result:309050.0
time:6297 ms
OK
84581920
309050.0
plugin
result:309050.0
time:47 ms
OK

20 Replies

It’d also be nice to see a C# version, how would that compare?

I’m not sure how to set that up. The max sdk samples and wizard are c++ as far as I can tell.

moreover it’d be more interesting if x and y varied in each loop – don’t often have the need for 5,000,000 times the exact same mult

Heh, true, but my code is adding the multiplication to the variable on each iteration, so there is definately math occuring each loop.

When I get a chance, I’m going to do some extensive speed comparisons and I’ll post them up here. I’m curious to see just how slow passing large arrays to a plugin actually is.

Ok. I adjusted the plugin so that the multiplications are different for each iteration.

Maxscript :


 
 k=0.0
 x=0.2
 y=0.3
t1= timestamp()
 for i = 1 to 10000000 do (
 	k+=(x+i)*(y-i)
 )
 format "Maxscript:Result:% Time:%ms
" k (timestamp() - t1)
 
 t1= timestamp()
 fpbasics.products x y
 format "sdk:Result:% Time:%ms
" k (timestamp() - t1)
 
 

C++:


  float FP_Basic::products(float x, float y)
 {
 	int i;
 	float k;
 	k = 0;
 	
 	for (int i = 0; i < 10000000; i++)
 	{
 		k += (x+i) * (y-i);
 	}
 	
 	return k;
 	
 }
 
  

Listener

Maxscript:Result:-3.36984e+020 Time:12328ms
OK
43304234
-3.33543e+020
sdk:Result:-3.36984e+020 Time:31ms
OK

So… SDK is only 397 times faster for a simple looped function…

I assume there’s no flaw in my code that skews the result in favour of the SDK? My last attempt at a benchmarking test was embarrasingly flawed!

C++ is faster than MAXScript and C# for sure.
But it’s faster to develop in MAXScript than in C++… So you have to choose depending on the complexity and use of your tool.
The best choice for me is to have a core interface in C++ for the hard computing tasks and a script to call this core and build the UI (it’s a pain designing UI in MFC or Win32).

Yep, that’s what I’m intending to do. I have a script that I’ve optimised as much as is possible, but I need it to run faster so I’m hoping to transfer some functions into c++.
I knew C++ would be faster but it’s nice to see quite how much faster it is!

As long as the for loop logic is included in C# (like Patrick did for C++), C# would hands down outperform both. Even considering the cold startup overhead on the CLR and the potential overhead of calling a C# method from Max would likely be bigger than that of C++.

Light

Interesting. What makes c# faster than c++? (please excuse my ignorance of the subject!)

Given that all the SDK samples and howto files are in C++ and the wizard is c++ I’m in no position to try to make a c# equivilent of the speed test I’m afraid! Is it even possible to compile a c# program as a .gup?

Are you an Oilers fan?

Page 1 / 2