Notifications
Clear all

[Closed] group faces by SetFaceColor

if you write greater/less comp function on c++ it will be probably 2 times faster

not quite (my old technical director would have a fit if he saw this )

int	comp(float x, float y) { return (x < y) ? -1 : (x > y) ? 1 : 0; }

is 5% slower than the c++ difference version with the same x2 mem issue.

i’ve just tried it ((a == b) ? 0 : (a < b) ? -1 : 1)
it makes qsort 3! times faster than comp1 and comp2. but it has x2 mem issue too.

it’s interesting that the new style function publish routines are 2 times slower than a paired down old style exposing techinques. In this case where you know the function arguments before hand there are real speed dividends.

Value* Comp1fn_cf(Value **arg_list, int count)
   {
   	float a = arg_list[0]->to_float();
   	float b = arg_list[1]->to_float();
   	return Integer::intern((int)(1e07f * (a - b)));
   }
   
   Value* Comp2fn_cf(Value **arg_list, int count)
   {
   	float a = arg_list[0]->to_float();
   	float b = arg_list[1]->to_float();
   	return Integer::intern((a < b) ? -1 : (a > b) ? 1 : 0);
   }

are so close it’s impossible to say which is faster (both being about 3.75 times faster than the original mxs comp1/comp2), and I think it would be difficult to gain any more performance against the overhead of the qsort it’s self.

and I think it would be difficult to gain any more performance against the overhead of the qsort it’s self.

I don’t think I could have been more wrong if I tried ! :surprised

pairing down to this…

int qsort_compare_float_fn(const void * p1, const void * p2)  
{
	float a = (*(Value **)p1)->to_float();
	float b = (*(Value **)p2)->to_float();	
	return (a < b) ? -1 : (a > b) ? 1 : 0;
}

Value* qsortf_cf(Value **arg_list, int count)
{
	Array* theArray = (Array*)arg_list[0];
	qsort(&theArray->data[0], theArray->size , sizeof(Value*), qsort_compare_float_fn);
	return Integer::intern(theArray->size);
}

is 64 times faster than the original comp1 & comp2 with mem usage of 68L ???

do you not miss anything? it’s cool but about ~2 times slower than sort
but it may be a very cool function if you could pass an array of structures and sort them by a specified property. that will be a real SAVER!

that qsortf function is 2 – 2.5 times faster than max sort on my setup.

but it may be a very cool function if you could pass an array of structures and sort them by a specified property. that will be a real SAVER!

isn’t a struct in mxs just another version of a mxs array (which in c++ is an array of value pointers) so your function should be possible.

hmm… what is your result for:


 (
 	seed 0
 	ar4 = for k=1 to 100000 collect (random -1.0 1.0)
 	gc()
 	
 	t1 = timestamp()
 	m1 = heapfree
 	sort ar4
 	format "s >> t:% m:%
" (timestamp() - t1) (m1 - heapfree)
 	format "	%
" (gethashvalue ar4 0)
 )
 (
 	seed 0
 	ar5 = for k=1 to 100000 collect (random -1.0 1.0)
 	gc()
 	
 	t1 = timestamp()
 	m1 = heapfree
 	qsortf ar5
 	format "f >> t:% m:%
" (timestamp() - t1) (m1 - heapfree)
 	format "	%
" (gethashvalue ar5 0)
 )
 

mine is

s >> t:54 m:120L
 	182459010
 f >> t:87 m:120L
 	182459010
1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

it’s possible for sure. just it will be some trouble for write qsort comparison function which takes three arguments (where the third arg is a property name).

typically this, but qsortf has been as low as 32

sort >> t:94 m:68L
	182459010
OK
qsortf >> t:47 m:68L
	182459010
1 Reply
(@denist)
Joined: 1 year ago

Posts: 0

what max version is it?

one thing I have noticed while playing around with extending mxs with the sdk is how well optimized mxs is (in places)…

sqrt, normalize, dot, cross etc you be hard pressed to get better performance even using optimized game engine stuff.

Page 4 / 5