question

Ankur A3 avatar image
0 Likes"
Ankur A3 asked Ankur A3 commented

Making code faster using Global Variable?

Hi Team,

I am trying to optimize my model in terms of code. But I think I need some more understanding to make it successful.

Let say I have this code in my model:

Table("Inputs").addRow();

Table("Inputs")[Table("Inputs").numRows][1]=Table("Inputs").numRows;


Now, I have taken the reference of global table as global variable and I am using it in my model:

Table(GV_Inputs).addRow();

Table(GV_Inputs)[Table(GV_Inputs).numRows][1]=Table(GV_Inputs).numRows;


I read in many post that if we use global variable, it works better. But it doesn't make any time difference for me.

Whether I am using it in the right way?

Thank you!

FlexSim 23.1.0
codescriptmodel optimization
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Ankur A3 commented

Adding 3.8 million rows using the method you outline takes 6.416 seconds on my machine.

Using a Table local variable reduces that to 5.3 seconds.

Then changing the table to a bundle reduces it to 0.32 seconds.

The test script:

  1. double start=realtime(1)+realtime(2)/1000;
  2. Table t=Table("GlobalTable1");
  3. for (int n=3800000;n>0;n--){
  4.     t.addRow();
  5.     t[t.numRows][1]=t.numRows;
  6. }
  7. return realtime(1)+realtime(2)/1000- start;

· 5
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.