question

Patrick Cloutier avatar image
0 Likes"
Patrick Cloutier asked Jordan Johnson edited

Which of these 2 programming methods is faster?

Over the years, I have been modeling something using 2 different methods but in different projects so I don't have a model that is done both ways to compare A vs B. So I'm asking the programming experts out there for their opinion.

Here it is.

I have 50 different products going through a production process. Each product has specific set-up, process times, qty per container, and a bunch of other information related to it. Lets say there are 15 fields of information for each of the 50 products. And these products flow in the thousands in the factory.

I have used 2 methods to threat this information:

Method A: Keep all this info in a global table of 50 lines X 15 columns and reference the appropriate info whenever it is needed throughout the model. So I look at the global table thousands and thousands of time during a simulation a run.

Method B: Copy all this info to 15 labels on each item when creating it and never look at the global table again during the simulation. Info is read of the product labels as needed. But each of the thousands of item in production carry 15 labels with them.

Which is better? or faster? or more efficient?

I used to use method A but now I mostly use method B but, as I said, I don't have a model that compares both.

Thanks for your input,

FlexSim 20.0.3
global tablelabels
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

·
Jordan Johnson avatar image
7 Likes"
Jordan Johnson answered Jordan Johnson edited

It really depends on the model.

For any given model, there may be a way to improve memory use or execution speed or even both. Some models are small enough that even egregious misuse of resources will go unnoticed. Some models are so large that a even small mistakes can cost big memory or CPU time.

Also, some things are easy to use (like ORDER BY statements) that sometimes have hidden performance costs. If you needed something ordered, but had to do it without an ORDER BY, it might be a huge pain, both to create and to maintain. If it's super complicated and fast, is that better than being simpler and slower? It all depends on what you, the modeler, need and want.

You could consider a Method C: assign the most commonly used values as labels, and leave the rest to look up in the table.

Or you could consider Method D: put all the columns of the row into an array, and put that array on one label on each item.

Or you could consider Method E: Use one token per row in the table, and add a reference to that token on all your flowitems.

There are many more variations on this theme. You can pick one and use it every time if you want; just be aware that no one approach is the clear winner in all situations.

In version 20.1, we added a new Performance Profiler and a Memory Profiler. You can use these tools to identify how your CPU time and RAM are being used by the model. That way, instead of theorizing about what might be faster, you can see what's happening, and make a more informed decision. You could even try something and see if it helped or not.

· 2
5 |100000

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

Patrick Cloutier avatar image Patrick Cloutier commented ·

Thanks a lot for the answer Jordan.

But method D brings up the question: Why is putting all 15 fields in one array on a label better than putting it on 15 different labels?

Also, fields are not all the same data type. Some are strings and some are numbers so can I place different data types in the same array?

0 Likes 0 ·
Jordan Johnson avatar image Jordan Johnson ♦♦ Patrick Cloutier commented ·

Method D would use less memory, since there would only be 1 treenode for 15 values. It might be more of a pain to use, though, since you would need to access the value by index instead of by name:

token.RowData[3] // get column 3's value

If you use an Array, you can put any Variant value into an array:

Array theArray = [1, 2];
theArray.push(3);
theArray.push("hello");
theArray.push(Model.find("Tools"));
print(theArray); // prints Array[5]: {1,2,3,hello,/Tools}
0 Likes 0 ·

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.