# Maxscript optimisation 101

 12 December 2008 reForm Expert portfolio Patrick Macdonald CG Artist reForm Studios London, United Kingdom Maxscript optimisation 101 To save you reading through this thread, head over to http://www.tech-artists.org/wiki/Performance_Tests_(MAXScript) where there are extensive code speed comparisons Hi, After watching some of Bobo's cgacademy video on The Matrix, it occured to me that there are quite a few functions I've been using that could have been scripted directly. With that thought I checked to see the speed comparison. My first test was using the cross product to calculate area rather than the meshop.getfacearea command. The results were surprising in one way, but I guess to be expected! With 10000 iterations: meshop.getfacearea = 0.281 seconds cross product method = 0.11 seconds That to me is a substantial difference. Maybe it would be helpful for everyone if we added scripted versions of standard maxscipt functions that offered similar speed advantages to this thread. Along with the geometric functions sticky I think this could be a handy resource. Here's the code for the area speed test that you can use as a basis for future speed tests. `````` theobj=\$plane01 --You will need to make this plane and convert to editable_mesh! theface = getface theobj 1 thevert1 = getvert theobj theface.x thevert2 = getvert theobj theface.y thevert3 = getvert theobj theface.z thevector1 = thevert2 - thevert1 thevector2 = thevert3 - thevert1 iterations=100000 fn area1 = ( for i = 1 to iterations do thearea1 = (length (cross thevector1 thevector2))/2 ) fn area2 = ( for i = 1 to iterations do thearea2 = (meshop.getfacearea theobj 1) ) start = timeStamp() area1() -- do some big job end = timeStamp() format "Processing area1 took % seconds\n" ((end - start) / 1000.0) start = timeStamp() area2() -- do some big job end = timeStamp() format "Processing area2 took % seconds\n" ((end - start) / 1000.0) `````` __________________ Patrick Macdonald Lighting TD : http://reformstudios.com Developer of Mission Control , the spreadsheet editor for 3ds Max Last edited by reForm : 12 December 2008 at 11:26 AM. share quote
 12 December 2008 RobGalanakis Frequenter   portfolio Rob Galanakis Technical Animator Bioware Austin Austin, USA http://www.tech-artists.org/wiki/Pe...sts_(MAXScript) Sorry it is still a bit hidden from the main page, I have been putting off a major Wiki update for a while... can you add your info? __________________ Tech-Artists.Org, a Community for Technical Artists www.robg3d.com Last edited by RobGalanakis : 12 December 2008 at 03:59 PM. Reason: had to fix url share quote
 12 December 2008 Bobo Krakatoa Guy   Borislav Petrov Product Specialist Thinkbox Software Vancouver, Canada I am sorry, but this is the most misleading comparison I have ever seen. In the area1 test, you just iterate and calculate cross products, but do NOT access any face or vertex data inside the loop, while poor meshop.getFaceArea() still has to do it in every iteration. (It does pretty much the same internally, but in C++ and is faster than the scripted version once both are set to do the same). You cannot skip steps from the operation and claim that is faster Once you move all mesh access operations into the area1 function as it should be, it is slower - 1.5 seconds vs. 0.4 seconds on my home machine. `````` ( theobj=\$plane01 --You will need to make this plane and convert to editable_mesh! iterations=100000 fn area1 = ( for i = 1 to iterations do ( theface = getface theobj 1 thevert1 = getvert theobj theface.x thevert2 = getvert theobj theface.y thevert3 = getvert theobj theface.z thevector1 = thevert2 - thevert1 thevector2 = thevert3 - thevert1 thearea1 = (length (cross thevector1 thevector2))/2 ) ) fn area2 = ( for i = 1 to iterations do thearea2 = (meshop.getfacearea theobj 1) ) start = timeStamp() area1() -- do some big job end = timeStamp() format "Processing area1 took % seconds\n" ((end - start) / 1000.0) start = timeStamp() area2() -- do some big job end = timeStamp() format "Processing area2 took % seconds\n" ((end - start) / 1000.0) )`````` __________________ Bobo Last edited by Bobo : 12 December 2008 at 04:03 PM. share quote
 12 December 2008 reForm Expert portfolio Patrick Macdonald CG Artist reForm Studios London, United Kingdom Aha Bobo, no need to apologise! Thanks for putting me straight although I'm hurt to hear this is the worst you've ever seen! Still trying to make improvements in my maxscript skills but it seems I need to think more about my general logic too! I've been enjoying your cgAcademy tutorials and look forward to your future productions. __________________ Patrick Macdonald Lighting TD : http://reformstudios.com Developer of Mission Control , the spreadsheet editor for 3ds Max share quote
 12 December 2008 reForm Expert portfolio Patrick Macdonald CG Artist reForm Studios London, United Kingdom Originally Posted by RobGalanakis: http://www.tech-artists.org/wiki/Performance_Tests_(MAXScript) Sorry it is still a bit hidden from the main page, I have been putting off a major Wiki update for a while... can you add your info? Given the above post from Bobo I think I should refrain from polluting your excellent resource with my bad analysis __________________ Patrick Macdonald Lighting TD : http://reformstudios.com Developer of Mission Control , the spreadsheet editor for 3ds Max share quote
 12 December 2008 CGTalk Moderation Expert Thread automatically closed This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum. __________________ CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. share quote

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off CGSociety Society of Digital Artists www.cgsociety.org Powered by vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.
Forum Jump
 Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Gallery     Latest Entries     Featured 2D     Featured 3D     CG Awards     Community Awards Main     News     General Discussion     Off Topic     Recruitment         Temp Job Board Challenges     Rival Crimson X Chaos     Education     Demo Reel     Portfolio Review GROUPS WIP ADVICE     Pro Select     Art Direction and Interviews     New 2D/3D Sketchbooks 2018     WIP 2D/3D & Animation         WIP/Critique: 3D         WIP/Critique: 2D             Speedpaints & Sketchbooks         WIP/Critique: Animation     Partners and Groups         Kitbash 3D Thunderdome         Collaborative Projects Autodesk     Autodesk Maya         Maya Dynamics         Maya Rendering         Maya Character Setup         Maya Programming     Autodesk Miscellaneous         Autodesk MotionBuilder         Autodesk Mudbox         Autodesk Softimage             XSI: Programming             ICE: Interactive Creative Environment     Autodesk 3ds max         3dsMax Tutorials & Tips         3dsMax Resources         3dsMax SDK and MaxScript         Plugins & Add-ons         Particle Flow     Mudbox Featured Gallery ZBrush     Featured Zbrush Gallery     Pixologic ZBrush     Keyshot     Marvelous Designer Texturing     Allegorithmic Substance         Substance Designer         Substance Painter         Substance Featured Gallery     Texturing XYZ     Mari     Marmoset Toolbag Software     Maxon Cinema 4D         Cinema 4D Resources     Side Effects Houdini     Compositing Software         The Foundry Nuke         Adobe After Effects         Autodesk Effects and Compositing         Eyeon Software Digital Fusion     Additional Software         Lightwave 3D             LW Resources             LW Tutorials         The Foundry Modo             The Foundry Time Travel Challenge         E-on Software Vue         Photoshop / Painter         Blender         3DCoat Techniques     Art Techniques and Theories     Digital Matte Painting         Digital Matte Painting Mini-Challenge     Modeling         Modeling Challenge             Member Model Collection     Texturing and Surfacing     Character Rigging     Animation     Lighting and Shaders         Lighting Challenges     Compositing and Editing     Anatomy and Figurative Art         SPOTLIGHT: Best of the Artistic Anatomy and Figurative Art Forum         Tutorials and Workshops         Personal Anatomy & Sketchbook Threads         References, Resources, and Supplies Technical     VR/AR     Master Virtual Reality with BrioVR     Workstation Builds     Game Engine     Graphics Programming     Technical and Hardware
Miscellaneous

All times are GMT. The time now is 07:58 AM.