10 Replies Latest reply on Feb 4, 2013 7:14 AM by Trevorׅ

    Speed Test for AS3 JS & C++

    Trevorׅ Adobe Community Professional

      I'm interested in the comparative speeds of a script written in AS3, JS and C++

       

      I can only test the JS script myself so I'd like some nice friendly bloke to fill the gap and run the script from the AS3 sdk cs extension builder environment and if there's some really kind soul out there to do a test on a c++ version of the script that would be great!

       

      P.s. I am not partially interested in lectures on the uselessness of the test as some languages are better and quicker at different things than other ones etc.etc. etc.

       

      Below is the test script, it should take about a minute to run depending on which decade - century - millennia your computer was made in but you can change the c < 10000 to c < 2000 if you are actually doing some real work.

       

       

      Please fill in this table

       

      JS
      ASC++



      Fast Undo Mode



      Entire Undo Mode



      Function

       

      Thanks in advance,

       

      Trevor

       

      var fastStartTime = new Date().getTime() / 1000;
      app.doScript("main()", undefined, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Fast Change letter order");
      var entireStartTime = new Date().getTime() / 1000;
      app.doScript("main()", undefined, undefined, UndoModes.ENTIRE_SCRIPT, "Entire Change letter order");
      var functionStartTime = new Date().getTime() / 1000; 
      main()
      var functionEndTime = new Date().getTime() / 1000; 
      
          alert ("The Fast undo mode took " + (entireStartTime - fastStartTime) + " seconds." +
          "\nThe Entire undo mode took " + (functionStartTime - entireStartTime) +  " seconds." +
          "\nThe function took " + (functionEndTime - functionStartTime) + " seconds.")
      
      
      function main()
      {
          var doc = app.activeDocument, c, l, myCharacters = doc.stories.everyItem().characters.everyItem().getElements();
          l = myCharacters.length;
          for (c = 1; c < 10000; c++) myCharacters[c %  l].move (LocationOptions.AT_BEGINNING, myCharacters[c %  l].parentStory);
      }
      
        • 1. Re: Speed Test for AS3 JS & C++
          MrTIFF Level 3

          I don't remember how to do InDesign C++ any more, but here are a few results for JS and AS. I'm sure others will chime in a well.

           

          On my machine, with my test page filled with text, InDesign CS6, Mac, and looping only 500 times:

           

          JavaScript (ExtendScript):

            Fast Undo:  16.39 s

            Entire Undo:  33.14 s

            Function:    32.95 s

           

          ActionScript:

             Fast Undo:     not easily done

             Entire Undo:  not easily done

            Function:    31.35 s

           

          The problem is that, although there is a doScript() function in ActionScript, it can only run JavaScript, AppleScript, or VBScript,

          which doesn't really get at what you want to test.

          1 person found this helpful
          • 2. Re: Speed Test for AS3 JS & C++
            MrTIFF Level 3

            Sorry, hit 'Send' too soon.

             

            This is consistent with other timing tests that I have run in the past. ActionScript IS faster than ExtendScript for number crunching, etc, but calls to the DOM to get InDesign to DO something are comparatively much more expensive -- and ActionScript uses the same interface to InDesign as does ExtendScript.  So for both languages, reducing the number of calls made to the InDesign DOM is often the most effective way to get performance improvements.

            1 person found this helpful
            • 3. Re: Speed Test for AS3 JS & C++
              Harbs. Level 6

              stephen0218 wrote:

               

              and ActionScript uses the same interface to InDesign as does ExtendScript.

              Actually, ActinScript DOM objects are just proxies for ExtendScript objects, so when you are accessing the DOM, it IS ExtendScript working...

              • 4. Re: Speed Test for AS3 JS & C++
                Trevorׅ Adobe Community Professional

                Stephan,

                 

                Thanks for reply, I marked them as helpful and would like to get some more feedback, with some info on the C++.

                 

                The results are very interesting to me.

                 

                I am a bit surprised that the script took so long to run for a loop of 500. My Windows 7 Intel core2 duo thinkpad from about the end of 2009 run the 3 JS scripts in about 3, 5 and 6.5 seconds, so you probably could do with a bit of a clean up (registry / disk)on your Mac. To run the 10000 loop the JS scripts took 11.75, 18 and 20.4 seconds for the 3 running modes.

                 

                According to your results, if the script is DOM orientated then there's no real speed advantage of using AS3 as opposed to JS.

                 

                One advantage of AS3 is that using the extension builder one can create dockable native looking panels.

                 

                Can anyone think of any other advantages of using AS3?

                 


                • 5. Re: Speed Test for AS3 JS & C++
                  Trevorׅ Adobe Community Professional

                  Thanks Harbs,

                  Any news on the c++

                  • 6. Re: Speed Test for AS3 JS & C++
                    MrTIFF Level 3

                    Note that the running time of your test depends greatly on how many characters you have in your story. When I cut my story in half (from 5000 down to 2500 chars), it runs more than 2 times as fast, even though it is looping just as many times.

                     

                    Yes, if your script is dominated by DOM calls -- and most ExtendScripts are -- there is often no speed advantage of using AS3.

                     

                    Other arguments for using AS3: AS3 is a strongly typed language, meaning that the compiler will complain if you try to try to do something like call Math.max() on two Document objects. So you don't have to wait until runtime to know that you have a problem. And AS3 has true Classes, which makes AS3 more more immediately palatable to C++ and Java programmers.

                     

                    There are really a lot of pros and cons for using ExtendScript vs Flex/ActionScript/Extension Builder. I've just touched on some of them. My feeling is that Flex is probably better for larger, more complex projects, and for building dockable palettes, with ExtendScript getting the nod for smaller projects. Usually.

                    • 7. Re: Speed Test for AS3 JS & C++
                      Harbs. Level 6

                      Here's some pros and cons to different approaches:

                      http://in-tools.com/article/thoughts-on-extending-the-creative-suite/

                      • 8. Re: Speed Test for AS3 JS & C++
                        Trevorׅ Adobe Community Professional

                        Harbs

                         

                        I saw that article quite some time ago and left a comment on it 2+weeks ago.

                         

                        My 2 questions there were the speed and functionality of AS3

                         

                        It would seem the that regarding the speed there's not much in it. And the main diference in functionality is the UI.

                        I am not sure if the AS has any additional feature other than the UI.

                         

                        One thing that stuck me when I read your article was what you wrote,

                        "Another advantage to Flash dialogs is the ability to change properties in InDesign’s DOM while a modal dialog is open. This is something not possible using Script UI." - my bolding and underlining.

                         

                        This is true with a "dialog" but not with a "palette" or "window" which cause no problem with changing the DOM.

                        With event listeners one can also display the properties, but I was wondering if this could be done more efficiently with AS. Is this the case?

                         

                        C++ has from what I understand a much much richer functionality, my remaining question on C++ is how much quicker is it than the "scripting" methods when it comes to DOM processing of the type illustrated by my sample script.

                         

                        Stephan,

                         

                        You have a good point about the document length, makes perfect sense.  I was testing it on a document with about 200 - 300 words.

                        I've often heard that one should always weigh a baby on the same scale!

                        • 9. Re: Speed Test for AS3 JS & C++
                          Harbs. Level 6

                          ~ Trevor ~ wrote:

                           

                          Harbs

                           

                          I saw that article quite some time ago and left a comment on it 2+weeks ago.

                           

                          My 2 questions there were the speed and functionality of AS3

                           

                          It would seem the that regarding the speed there's not much in it. And the main diference in functionality is the UI.

                          I am not sure if the AS has any additional feature other than the UI.

                          Not true. It really depends on what you're doing. For example, sorting data in AS3 is an order of a magnitude faster than sorting in ES. So if you have a script that does a lot of sorting, you'll see huge gains by doing it in AS. Stuff like network communication, databse interaction, etc. are all really good reasons to do extensions.

                           

                           

                          One thing that stuck me when I read your article was what you wrote,

                          "Another advantage to Flash dialogs is the ability to change properties in InDesign’s DOM while a modal dialog is open. This is something not possible using Script UI." - my bolding and underlining.

                           

                          This is true with a "dialog" but not with a "palette" or "window" which cause no problem with changing the DOM.

                          With event listeners one can also display the properties, but I was wondering if this could be done more efficiently with AS. Is this the case?

                          Yup. You can change the DOM in a CSXS Dialog similar to how you can in a ScriptUI palette.

                           

                           

                          C++ has from what I understand a much much richer functionality, my remaining question on C++ is how much quicker is it than the "scripting" methods when it comes to DOM processing of the type illustrated by my sample script.

                           

                          Again, the answer is a big "it depends". If most of the time in the script is InDesign doing complex stuff like recomposition (as in you sample script), the gains will not be that great. If a lot of the time is resolving javascript objects or really complex calculations, you'll see gains in C++.

                           

                          Of course if you need to add core functionality, that's where you really need C++...

                          • 10. Re: Speed Test for AS3 JS & C++
                            Trevorׅ Adobe Community Professional

                            Thanks Harbs

                             

                            That sums it up from my point of view, both your's and Stephans answers have thrown a lot of light on the topic.