question

Brandon Peterson avatar image
10 Likes"
Brandon Peterson asked Brandon Peterson commented

Do you have a faster more simple way to access data from Global Tables - Challenge Question

Recently I built a model that was simulating up to 1.35 million units per day and would run for up to 40 days. Obviously this is a lot of events and the model took longer than one of my typical models. When looking for ways to speed up the simulation I noticed that I was looking up and setting data in global tables multiple times for each of the 1.35 million units... OUCH!!

In the past I have used global macros to reference global tables when I use any of the global table commands. I did this for two reasons: First, I thought that it was faster than using strings (eventhough I did not have any empirical results to back me up). Second, it made the model a little easier to adjust when changes were made later in the life of the project. This model was no exception and I was using global macros to reference the tables.

So, my question is: Do you have a way of referencing the global tables that is faster and preferably as simple and robust as using global macros?

I plan on building a sample model to run some experiments of my own to answer this question. However, I believe that all of you out there are more than capable of having a better solution than myself. So, this is a "Challenge Question" in that I would like to challenge you to beat my answer and any others posted to this question. Over time I hope that we will all benefit by seeing all of the different methods/ways that this can be done.

Thanks and good luck!

Brandon

FlexSim 16.0.1
global tableglobal variablesrun timeglobal macroschallenge question
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

Brandon Peterson avatar image
10 Likes"
Brandon Peterson answered Brandon Peterson commented

All,

To answer the question and find a faster way to execute calls to the global tables I created the attached sample model. The model uses the FlexScript Code Profiler to determine the amount of time that it takes to call the gettablenum() command. The model was setup as follows:

  • 10 Global tables were added to the model using the default table names
  • Each global table was sized to 10x10
  • All of the cells toggled as numeric data and their values set to 0
  • Global macros were created to reference the rank of each table
  • Global variables were created to reference the table node
  • User commands were created to call gettablenum() from the 1st, 5th, and 10th tables with the table being passed in as a:
    • String – table name
    • Number – table rank
    • Macro – table rank with a global macro
    • Tree Node – table reference with a global variable

I then opened up a script window and entered some code to execute all 12 user commands a specified number of times.

In total all 12 commands were executed 44 million times in 8 executions of the script window code. I have attached an Excel file that contains all of the results along with some analysis/comparison calculations.

Here is a short summary of the results:

  • Tree node reference from a global variable was the fastest method that I tested. It was approximately 3X faster than using a string with the table name.
    • Tree Node – Fastest at 33% of String
    • Macro – Second Fastest at 64.9% of String
    • Number – Third Fastest at 66% of String (Only slightly slower than Macro)
    • String - Slowest
  • The rank of the global table has a slight impact on the speed depending on the method used to reference the global table
    • String – (1,5,10) - lower ranked tables were faster
    • Number – (5,10,1) - the middle table was fastest, followed by the last with the first being slowest
    • Macro – (10,5,1) – lower ranked tables were slower
    • Tree Node – (10,5,1) – lower ranked tables were slower

In the past I would almost exclusively us global macros to define the ranks of my tables and then use the macros in my code. My conclusion from this experiment is that I have been using the wrong (i.e. slower) method. I will be switching over to using global variables to reference my global tables for all of my future models.

I hope that this was as helpful to you as it was to me. Even more, I hope that one of you will have an even faster and more simple method for me to use!

Brandon


· 4
5 |100000

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