Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Execution time

New Here ,
Sep 25, 2013 Sep 25, 2013

I have 2 bits of code that do the same thing. They take frames and override them on a page.

Next I link the frames.

My master page has 100 frames, and in a document I have 50 pages.

I get these results when I measure time:

1. 147 seconds

2. 223 seconds

These are bits of code:

1.

masterPg.textFrames.everyItem().override(myDocument.pages.item(0));

for (pg=1; pg<50; pg++) {

     page=myDocument.pages.item(pg);

      masterPg.textFrames.everyItem().override(page);

      for (var frameNumb=0; frameNumb<framesTotal; frameNumb++) {

         txt1=myDocument.pages.item(pg-1).textFrames.item(frameNumb);

          txt2=myDocument.pages.item(pg).textFrames.item(frameNumb);

          txt1.nextTextFrame=txt2;

       }

   }

2.

for (var pg=0; pg<50; pg++) {

    page=myDocument.pages.item(pg);

    masterPg.textFrames.everyItem().override(page);

   }

for (pg=1; pg<50; pg++) {

        for (var frameNumb=0; frameNumb<framesTotal; frameNumb++) {

         txt1=myDocument.pages.item(pg-1).textFrames.item(frameNumb);

          txt2=myDocument.pages.item(pg).textFrames.item(frameNumb);

          txt1.nextTextFrame=txt2;

           }

   }

I cannot explain the time difference! 1 extra for loop in the second bit can’t be the problem because it loops only 50 times?! or?

Maybe object cache is the problem?

Please help!?

TOPICS
Scripting
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 29, 2013 Sep 29, 2013

If framesTotal is high, I would say that is the cause.

The second loop in example 1 will run 50 * framesTotal in example 2.

compare.PNG

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2013 Sep 30, 2013

The difference in the code is only 1 extra for loop. Nothing else.

All the code is running same amount of times in examples, I mean it gets executed the same amount of times.

I think that ExtendScript engine has some optimization for this (memory management?!), but i don’t know which optimization because I can’t find any documentation on the engine and the way it works.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 30, 2013 Sep 30, 2013

You have 1 extra loop in example number 2 (looping 50 times). But inside that loop you still do the same loop that you have got in example number 1.

Where is framesTotal set? And what is the value of it?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 30, 2013 Sep 30, 2013

framesTotal is 100 frames, and I have them on a master page.

The extra for loop in the second example is a loop that I use to override all master text frames on every page.

In first example I deleted that loop, and pages get overriden in the second loop.

I do overriding of frames the same amount of times in both examples. 5000 frames total get overridden.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 01, 2013 Oct 01, 2013

Yes, sorry, you are right, my mistake.

Could you check whether the time for  linking is low at first, and then increasing in sample 1, and if the time to relink is long, from the beginning, in sample 2?

And / or time the override calls, to get to know what part of the code that is the problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 01, 2013 Oct 01, 2013

I have already measured the times

First example;

Override 89 sec

Linking 41 sec

Second example;

Override 96 sec

Linking 137 sec

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Oct 01, 2013 Oct 01, 2013

The difference is caused by the extra for. More exactly it is caused by the extra DOM acess. Your first script goes over 50 pages, and for each it does it stuff. The second one, goes over 50 pages, overrides everything, then again goes over 50 pages and links stuff. Quite a lot more overhead.

Now, there are quite a lot of ways you can optimize even the first one (i am assuming all your variables are predeclared somwhere, not globals).

For examle, just replacing the txt2 line to something like this:

txt2=page.textFrames.item(frameNumb);

will give you a nice speed boost (general javascript object caching).

Add just before closing the outer loop a line like:

prevPage=page;

and change the txt1 line to

txt1=prevPage.textFrames.item(frameNumb);

and the execution time will be.. i don't know, but i'm guessing about half..

also, make sure you have scriptRedraw set to false.

Good luck

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 02, 2013 Oct 02, 2013
LATEST

Actually, at the end I did this and got the best times….

     for (pg=1; str<50; pg++) {

             framesMaster.override(pgDoc.item(pg));

             page1=pgDoc.item(pg).textFrames.everyItem().getElements();

             page=pgDoc.item(pg-1).textFrames.everyItem().getElements();

        for (frameNumb=0; frameNumb<framesTotal; frameNumb++) {

             page[frameNumb].nextTextFrame=page1[frameNumb];

             }

       }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines