question

Enrique Elizaga avatar image
0 Likes"
Enrique Elizaga asked tannerp commented

are queries faster than running a for or while cycle?

In my models I am working a lot with tables, sometimes big tables.

To get values I have been using FOR and WHILE to copy cell by cell.

Aside from syntax simplicity are there any advantages in performance when using query commands to get values from tables?

FlexSim 18.2.3
query
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

·
christian.n avatar image
4 Likes"
christian.n answered

Hi Enrique

In my experience, queries tend to work quite fast. I can't say for sure whether you will save CPU time without knowing the operation you are performing on your table.

If you are performing sorting operations, queries are significantly faster than traditional sorting table operations. A lot of CPU time can also be saved by using tables with bundle data compared to regular table data.

You can test the amount of time an operation takes by using a script like this:

Table table = Table("GlobalTable1");

//set table size to 20000 rows, 4 cols
table.setSize(20000,4);

//Fill 1st row with random values
for(int x=1;x<=table.numRows;x++) table[x][1] = uniform(0,100);

//Make a time stamp of the start time of your process (accurate down to a millisecond)
double timestamp = realtime(1)+realtime(2)/1000;

//sort table by 1st row
table.sort(1);

//Return the difference in time from when the time stamp was made
return realtime(1)+realtime(2)/1000-timestamp;

The script will return the time an operation takes to perform - in the case above it is the sorting of the table itself.

I hope this helps.

5 |100000

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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