Forums > MaxMSP

the more efficient ?

July 28, 2007 | 8:14 pm

Hello,

Here is a little patch with two identical process.
I have many process like these in a bigger patch and need to have your opinion : what is the more efficient way ?
Examples in my patch give the same results.

thank you.

max v2;
#N vpatcher 155 112 898 756;
#P window setfont "Fixedwidth Serif" 10.;
#P newex 433 100 58 1441802 loadbang;
#B color 11;
#P newex 426 281 34 1441802 pack;
#B color 11;
#P user pictslider 224 50 100 100 4 4 4 4 SliderDefaultKnob.pct 0 SliderDefaultBkgnd.pct 0 2163 0 8323072 127 1. 1.;
#P window setfont "Sans Serif" 18.;
#P message 395 513 153 196626 55 51 55 51;
#P window setfont "Fixedwidth Serif" 10.;
#P newex 395 493 76 1441802 prepend set;
#P window setfont "Sans Serif" 18.;
#P message 228 513 153 196626 55 51 55 51;
#P window setfont "Fixedwidth Serif" 10.;
#P newex 228 493 76 1441802 prepend set;
#P newex 275 224 41 1441802 unpack;
#B color 11;
#P newex 292 250 41 1441802 unpack;
#B color 11;
#P window setfont "Sans Serif" 9.;
#P message 401 138 49 196617 150 150;
#P message 457 139 49 196617 100 100;
#P window setfont "Fixedwidth Serif" 10.;
#P newex 148 464 97 1441802 pack 0 0 0 0;
#P window setfont "Sans Serif" 9.;
#P comment 245 453 23 196617 + Y;
#P comment 171 453 22 196617 – Y;
#P comment 216 453 23 196617 + X;
#P comment 143 453 22 196617 – X;
#P newex 227 351 96 196617 gate 4;
#B color 11;
#P comment 101 317 48 196617 x;
#P comment 253 317 48 196617 y;
#P newex 244 372 96 196617 gate 4;
#B color 11;
#P newex 311 394 27 196617 i;
#B color 11;
#P newex 283 394 27 196617 i;
#B color 11;
#P newex 255 394 27 196617 i;
#B color 11;
#P newex 227 394 27 196617 i;
#B color 11;
#P newex 138 435 27 196617 -;
#B color 13;
#P newex 167 435 27 196617 -;
#B color 11;
#P newex 239 435 27 196617 +;
#B color 11;
#P newex 210 435 27 196617 +;
#B color 13;
#P newex 205 330 118 196617 t i b;
#B color 4;
#P newex 71 330 118 196617 t i b;
#B color 6;
#P newex 110 374 96 196617 gate 4;
#B color 13;
#P newex 177 396 27 196617 i;
#B color 13;
#P newex 149 396 27 196617 i;
#B color 13;
#P newex 121 396 27 196617 i;
#B color 13;
#P newex 93 396 27 196617 i;
#B color 13;
#P newex 275 295 27 196617 / 2;
#P newex 304 295 27 196617 / 2;
#P newex 275 272 27 196617 -;
#P newex 304 272 30 196617 -;
#P newex 93 352 96 196617 gate 4;
#B color 13;
#P comment 382 404 29 196617 x , y;
#P newex 551 273 27 196617 t b l;
#P newex 613 293 36 196617 zl reg;
#P newex 411 403 54 196617 unpack 0 0;
#B color 13;
#P comment 535 405 29 196617 x , y;
#P newex 480 404 54 196617 unpack 0 0;
#B color 13;
#P window setfont "Fixedwidth Serif" 10.;
#P newex 411 465 112 1441802 pack 0 0 0 0;
#P window setfont "Sans Serif" 9.;
#P comment 518 455 23 196617 + Y;
#P comment 444 455 22 196617 – Y;
#P comment 489 455 23 196617 + X;
#P comment 416 455 22 196617 – X;
#P newex 411 437 27 196617 -;
#B color 13;
#P newex 440 437 27 196617 -;
#B color 11;
#P newex 512 437 27 196617 +;
#B color 11;
#P newex 483 437 27 196617 +;
#B color 13;
#P newex 411 317 141 196617 t l b;
#B color 4;
#P newex 427 337 125 196617 gate 4 1;
#P newex 453 356 125 196617 gate 4 1;
#P newex 541 375 36 196617 zl reg;
#P newex 503 375 36 196617 zl reg;
#P newex 465 375 36 196617 zl reg;
#P newex 427 375 36 196617 zl reg;
#P comment 556 299 38 196617 mouse;
#P comment 616 277 54 196617 mouseidle;
#P newex 568 334 73 196617 vexpr $i1 / 2;
#P newex 568 313 81 196617 vexpr $i1 – $i2;
#P connect 63 0 36 0;
#P connect 26 0 31 0;
#P connect 35 0 31 1;
#P connect 26 1 32 0;
#P connect 35 1 32 1;
#P fasten 36 0 41 0 76 432 143 432;
#P lcolor 7;
#P connect 41 0 54 0;
#P connect 26 2 33 0;
#P fasten 34 0 41 1 182 420 160 420;
#P lcolor 14;
#P fasten 33 0 41 1 154 420 160 420;
#P fasten 32 0 41 1 126 420 160 420;
#P fasten 31 0 41 1 98 420 160 420;
#P connect 35 2 33 1;
#P fasten 37 0 40 0 210 424 172 424;
#P lcolor 5;
#P connect 26 3 34 0;
#P connect 40 0 54 1;
#P connect 36 1 26 1;
#P fasten 45 0 40 1 316 419 189 419;
#P lcolor 12;
#P fasten 44 0 40 1 288 419 189 419;
#P lcolor 12;
#P fasten 43 0 40 1 260 420 189 420;
#P lcolor 12;
#P fasten 42 0 40 1 232 420 189 420;
#P lcolor 12;
#P connect 35 3 34 1;
#P fasten 30 0 35 1 280 314 201 314;
#P connect 63 1 37 0;
#P connect 38 0 54 2;
#P fasten 36 0 38 0 76 432 215 432;
#P lcolor 7;
#P connect 49 0 42 0;
#P fasten 34 0 38 1 182 420 232 420;
#P lcolor 12;
#P fasten 33 0 38 1 154 420 232 420;
#P lcolor 12;
#P fasten 32 0 38 1 126 420 232 420;
#P lcolor 12;
#P fasten 31 0 38 1 98 420 232 420;
#P lcolor 12;
#P connect 54 0 59 0;
#P connect 59 0 60 0;
#P connect 39 0 54 3;
#P fasten 37 0 39 0 210 425 244 425;
#P lcolor 5;
#P connect 46 0 42 1;
#P connect 49 1 43 0;
#P fasten 45 0 39 1 316 420 261 420;
#P lcolor 12;
#P fasten 44 0 39 1 288 419 261 419;
#P lcolor 12;
#P fasten 43 0 39 1 260 419 261 419;
#P lcolor 12;
#P fasten 42 0 39 1 232 420 261 420;
#P lcolor 12;
#P connect 46 1 43 1;
#P connect 56 0 58 0;
#P connect 58 0 28 0;
#P connect 28 0 30 0;
#P connect 49 2 44 0;
#P connect 55 0 57 0;
#P connect 57 0 28 1;
#P connect 46 2 44 1;
#P connect 58 1 27 0;
#P connect 27 0 29 0;
#P connect 49 3 45 0;
#P connect 37 1 49 1;
#P connect 57 1 27 1;
#P connect 46 3 45 1;
#P fasten 29 0 46 1 309 323 335 323;
#P connect 19 0 61 0;
#P connect 61 0 62 0;
#P connect 65 0 56 0;
#P connect 64 0 10 0;
#P connect 10 0 22 0;
#P connect 22 0 14 0;
#P connect 14 0 19 0;
#P connect 63 0 64 0;
#P connect 9 0 4 0;
#P fasten 20 0 14 1 485 424 433 424;
#P fasten 22 1 13 0 460 428 445 428;
#P connect 13 0 19 1;
#P connect 63 1 64 1;
#P connect 8 0 4 1;
#P connect 65 0 55 0;
#P fasten 20 1 13 1 529 424 462 424;
#P connect 9 1 5 0;
#P connect 11 0 19 2;
#P fasten 7 0 20 0 546 397 485 397;
#P fasten 6 0 20 0 508 397 485 397;
#P fasten 5 0 20 0 470 397 485 397;
#P fasten 4 0 20 0 432 397 485 397;
#P fasten 22 0 11 0 416 428 488 428;
#P connect 8 1 5 1;
#P fasten 20 0 11 1 485 424 505 424;
#P connect 9 2 6 0;
#P fasten 22 1 12 0 460 428 517 428;
#P connect 12 0 19 3;
#P connect 8 2 6 1;
#P fasten 20 1 12 1 529 424 534 424;
#P connect 9 3 7 0;
#P connect 10 1 9 1;
#P connect 56 0 24 0;
#P connect 8 3 7 1;
#P connect 24 1 0 0;
#P connect 0 0 1 0;
#P connect 1 0 8 1;
#P fasten 24 0 23 0 556 292 618 292;
#P connect 55 0 23 1;
#P fasten 23 0 0 1 618 311 644 311;
#P pop;


July 28, 2007 | 10:26 pm

It seems to me that are no significant differences between the two in terms of computational expense. The one on the right uses five or six less objects to achieve the same result, so I might go with that. I’m sure you know this – in both left and right instances, the chain of events linked to your loadbang is doing nothing because all gates are closed (gates default to closed if you don’t give them a second argument) and nothing is connected to the left inlets of the gates to control routing. You probably just left this aspect out when taking this from a larger patch.


July 29, 2007 | 4:44 pm

The method on the left is faster than the method on the right when tested with uzi>cputimer.

On my machine Left does 10,000 calculations in around 74ms right comes in at around 100ms. For this reason i’d go for the left.

j.


July 29, 2007 | 6:22 pm

John is right. The one on the left is faster. On my system (Windows XP running on a MacBook Pro) the left clocks in 10,000 calculations at between 25 and 35 msecs – depending on how I send the uzi, while the right side ranges between 40 and 90 msecs.


July 31, 2007 | 12:12 pm

derrickgiscloux schrieb:
> Here is a little patch with two identical process. I have many
> process like these in a bigger patch and need to have your opinion :
> what is the more efficient way ? Examples in my patch give the same
> results.

Despite the measurements others have done, there is one rule to follow:
If its in the scheduler world, don’t even think about efficiency, but
think about clarity. The more clear version is preferable, even if its
ten times slower.
Your example shows that both versions are not very clear, and though you
claim they do the same, they don’t do the same for me. This is a matter
of clarity and testing.

As you did not describe what the patch supposed to do, I can only
guess… I don’t know what all the gates are for, so I skip them…
If I just look at the labels you put in there, result had been even wrong…

Maybe this is more efficient? It will give the labeled result…

Ok, I know this is not what you wanted, but its as close as someone can
get out of your description.
Even the most experienced Max expert usually isn’t able to read
thoughts… Imagine others haven’t spent any time with your problem…

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 285 198 28 196617 !- 0;
#P newex 224 197 28 196617 !- 0;
#P window setfont "Fixedwidth Serif" 10.;
#P newex 433 100 58 1441802 loadbang;
#B color 11;
#P user pictslider 224 50 100 100 4 4 4 4 SliderDefaultKnob.pct 0
SliderDefaultBkgnd.pct 0 2163 0 8323072 127 1. 1.;
#P window setfont "Sans Serif" 18.;
#P message 224 390 153 196626 -88 -89 88 89;
#P window setfont "Fixedwidth Serif" 10.;
#P newex 224 361 76 1441802 prepend set;
#P window setfont "Sans Serif" 9.;
#P message 401 138 49 196617 150 150;
#P message 457 139 49 196617 100 100;
#P window setfont "Fixedwidth Serif" 10.;
#P newex 224 335 100 1441802 pack 0 0 0 0;
#P window setfont "Sans Serif" 9.;
#P comment 318 318 23 196617 + Y;
#P comment 244 318 22 196617 – Y;
#P comment 289 318 23 196617 + X;
#P comment 216 318 22 196617 – X;
#P comment 525 111 100 196617 ????;
#P connect 10 1 13 0;
#P connect 10 1 5 3;
#P connect 10 0 12 0;
#P connect 10 0 5 2;
#P connect 13 0 5 1;
#P connect 12 0 5 0;
#P connect 11 0 7 0;
#P connect 11 0 6 0;
#P connect 8 0 9 0;
#P connect 5 0 8 0;
#P window clipboard copycount 14;


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


August 2, 2007 | 8:45 am

>On my machine Left does 10,000 calculations in around 74ms right >comes in at around 100ms

Could you show me how to get that ?
Or perhaps there is an example somewhere to know efficiency of a system from a patch ??


August 2, 2007 | 8:24 pm

The uzi > counter method (shown below) is one way of timing how long it takes max to accomplish a set number of tasks.

Your question was about efficiency and this kind of timing is one way of measuring efficiency. Sometimes it can be very important when objects are constantly being polled or have to prosses large amounts of data.

I agree with Stefan about clarity being an excellent goal – however a check of speed can be very useful as in the following example which shows how occasionally the more complex solution can be much much more efficient….

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 493 105 26 196617 time;
#P flonum 431 102 59 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 431 52 15 0;
#N vpatcher 525 182 715 430;
#N comlet interval in ms is reported here;
#P outlet 66 173 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 96 82 13 196617 b;
#P newex 96 104 46 196617 cpuclock;
#P newex 66 143 27 196617 – 0.;
#P newex 48 82 13 196617 b;
#P newex 48 104 46 196617 cpuclock;
#N comlet bang stops timing and reports interval;
#P inlet 96 58 15 0;
#N comlet bang starts timing interval;
#P inlet 48 58 15 0;
#P connect 0 0 3 0;
#P connect 3 0 2 0;
#P connect 5 0 4 0;
#P connect 4 0 7 0;
#P connect 2 0 4 1;
#P connect 1 0 6 0;
#P connect 6 0 5 0;
#P pop;
#P newobj 431 76 55 196617 p cputimer;
#P newex 357 88 40 196617 uzi 10;
#P comment 448 52 26 196617 test;
#P comment 216 89 26 196617 time;
#P flonum 154 86 59 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 154 36 15 0;
#N vpatcher 525 182 715 430;
#N comlet interval in ms is reported here;
#P outlet 66 173 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 96 82 13 196617 b;
#P newex 96 104 46 196617 cpuclock;
#P newex 66 143 27 196617 – 0.;
#P newex 48 82 13 196617 b;
#P newex 48 104 46 196617 cpuclock;
#N comlet bang stops timing and reports interval;
#P inlet 96 58 15 0;
#N comlet bang starts timing interval;
#P inlet 48 58 15 0;
#P connect 0 0 3 0;
#P connect 3 0 2 0;
#P connect 5 0 4 0;
#P connect 4 0 7 0;
#P connect 2 0 4 1;
#P connect 1 0 6 0;
#P connect 6 0 5 0;
#P pop;
#P newobj 154 60 55 196617 p cputimer;
#P newex 80 72 40 196617 uzi 10;
#P message 357 133 182 196617 laptopHD://give/me/a/path/to/strip;
#P message 391 328 177 196617 strip;
#P newex 391 300 62 196617 prepend set;
#P newex 357 181 79 196617 t l l 0;
#P newex 438 194 68 196617 loadmess 47;
#P newex 391 273 32 196617 itoa;
#P newex 357 252 44 196617 zl slice;
#P newex 391 215 57 196617 zl sub 47;
#P newex 357 160 32 196617 atoi;
#P message 80 267 177 196617 strip;
#P newex 80 239 62 196617 prepend set;
#P message 80 162 182 196617 laptopHD://give/me/a/path/to/strip;
#P newex 80 208 82 196617 strippath;
#P comment 171 36 26 196617 test;
#P fasten 22 0 20 0 436 70 362 70;
#P connect 22 0 21 0;
#P connect 20 0 13 0;
#P connect 21 0 23 0;
#P fasten 20 2 21 1 392 110 423 110 423 97 491 97 491 71 481 71;
#P fasten 16 0 14 0 159 54 85 54;
#P connect 16 0 15 0;
#P connect 14 0 2 0;
#P fasten 14 2 15 1 115 94 146 94 146 81 214 81 214 55 204 55;
#P connect 15 0 17 0;
#P connect 13 0 5 0;
#P connect 8 0 11 0;
#P connect 11 0 12 0;
#P fasten 10 2 7 1 430 206 379 206 379 246 396 246;
#P connect 5 0 10 0;
#P connect 10 0 7 0;
#P connect 10 1 6 0;
#P connect 6 0 7 1;
#P connect 7 1 8 0;
#P connect 9 0 6 1;
#P connect 3 0 4 0;
#P connect 1 0 3 0;
#P connect 2 0 1 0;
#P window clipboard copycount 25;

Best,

John.


August 2, 2007 | 8:32 pm

Ooops i wired up the Uzi’s incorrectly – interestingly they give simmilar results either way and you might not expect that depending on your reading of the help file.

anyhow corrected patch follows…

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 471 93 26 196617 time;
#P flonum 409 90 59 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 409 40 15 0;
#N vpatcher 525 182 715 430;
#N comlet interval in ms is reported here;
#P outlet 66 173 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 96 82 13 196617 b;
#P newex 96 104 46 196617 cpuclock;
#P newex 66 143 27 196617 – 0.;
#P newex 48 82 13 196617 b;
#P newex 48 104 46 196617 cpuclock;
#N comlet bang stops timing and reports interval;
#P inlet 96 58 15 0;
#N comlet bang starts timing interval;
#P inlet 48 58 15 0;
#P connect 0 0 3 0;
#P connect 3 0 2 0;
#P connect 5 0 4 0;
#P connect 4 0 7 0;
#P connect 2 0 4 1;
#P connect 1 0 6 0;
#P connect 6 0 5 0;
#P pop;
#P newobj 409 64 55 196617 p cputimer;
#P newex 335 76 40 196617 uzi 10;
#P comment 426 40 26 196617 test;
#P comment 223 96 26 196617 time;
#P flonum 161 93 59 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 161 43 15 0;
#N vpatcher 525 182 715 430;
#N comlet interval in ms is reported here;
#P outlet 66 173 15 0;
#P window setfont "Sans Serif" 9.;
#P newex 96 82 13 196617 b;
#P newex 96 104 46 196617 cpuclock;
#P newex 66 143 27 196617 – 0.;
#P newex 48 82 13 196617 b;
#P newex 48 104 46 196617 cpuclock;
#N comlet bang stops timing and reports interval;
#P inlet 96 58 15 0;
#N comlet bang starts timing interval;
#P inlet 48 58 15 0;
#P connect 0 0 3 0;
#P connect 3 0 2 0;
#P connect 5 0 4 0;
#P connect 4 0 7 0;
#P connect 2 0 4 1;
#P connect 1 0 6 0;
#P connect 6 0 5 0;
#P pop;
#P newobj 161 67 55 196617 p cputimer;
#P newex 87 79 40 196617 uzi 10;
#P message 335 121 182 196617 laptopHD://give/me/a/path/to/strip;
#P window linecount 0;
#P message 369 316 16 196617;
#P window linecount 1;
#P newex 369 288 62 196617 prepend set;
#P newex 335 169 79 196617 t l l 0;
#P newex 416 182 68 196617 loadmess 47;
#P newex 369 261 32 196617 itoa;
#P newex 335 240 44 196617 zl slice;
#P newex 369 203 57 196617 zl sub 47;
#P newex 335 148 32 196617 atoi;
#P window linecount 0;
#P message 87 274 16 196617;
#P window linecount 1;
#P newex 87 246 62 196617 prepend set;
#P message 87 169 182 196617 laptopHD://give/me/a/path/to/strip;
#P newex 87 215 82 196617 strippath;
#P comment 178 43 26 196617 test;
#P fasten 22 0 20 0 414 58 340 58;
#P connect 22 0 21 0;
#P fasten 20 1 21 1 355 100 400 100 400 85 478 85 478 50 459 50;
#P connect 20 0 13 0;
#P fasten 14 1 15 1 107 103 140 103 140 87 228 87 228 62 211 62;
#P connect 2 0 1 0;
#P connect 1 0 3 0;
#P connect 3 0 4 0;
#P connect 9 0 6 1;
#P connect 7 1 8 0;
#P connect 6 0 7 1;
#P connect 10 1 6 0;
#P connect 10 0 7 0;
#P connect 5 0 10 0;
#P fasten 10 2 7 1 408 194 357 194 357 234 374 234;
#P connect 11 0 12 0;
#P connect 8 0 11 0;
#P connect 13 0 5 0;
#P connect 15 0 17 0;
#P connect 14 0 2 0;
#P connect 16 0 15 0;
#P fasten 16 0 14 0 166 61 92 61;
#P connect 21 0 23 0;
#P window clipboard copycount 25;


August 2, 2007 | 9:01 pm

Thank you very much for this show, which is very helpfull and welcomed.
However :
> I agree with Stefan about clarity being an excellent goal –

It’is difficult and probably displaced to provide and explain a full max patch in the forum.

I needed a clear answer about a "clear" problem… clear for me.
So I extracted a sample of my very complex patch and asked for help about what’s the faster way for this fragment.

>… As you did not describe what the patch supposed to do, I can >only guess… I don’t know what all the gates are for, so I >skip them…

My goal was not to show or share my work and explain what I did or will do about project etc…
Just gave two process given a same result (they do ! no ??), and asked for opinion and help about efficiency.

For me it sounds like technical request goes to philosophy answers I didn’t asked for.
But perhaps my experience with forum isn’t very advanced.

Finally, sure I agree about clarity being an important goal.
I hope I did here.

Thanks in any case.
Derrick


Viewing 9 posts - 1 through 9 (of 9 total)