Best way to define a constant in function/task scope
In my function (or task), I have a constant string that is only used inside that method. What is the best way to define it (for performance): const static string stuff = "stuff"; const string stuff = "stuff"; static string stuff = "stuff"; string stuff = "stuff"; Example on EDA Playground: http://www.edaplayground.com/s/4/1090
const will prevent future writes, IEEE std 1800-2012 § 6.20.6 "Const constants" states "... a const can be set during simulation ..." which suggests that it is up to the vender to decide if there should be any optimization for performance. static will put the variable into shares memory. It could help or hurt performance depending on the simulation scenario. Actual performance impact is simulator specific, so you will need to run your own benchmarks. IEEE std 1800-2012 § 6.21 "Scope and lifetime" for more. For a small project, the performance impact will be negligible. For large projects, performance needs to be split into categories: memory usage, and memory access time. static variables can have trade-off smaller memory footprint (shared memory) and longer look-up times (memory address of the static variable can be faraway for the rest of the object data). const is unlikely to add any negative performance. Easiest way to get some basic performance data is to end the simulation with $finish(2). See IEEE std 1800-2012 Table 20-1—Diagnostics for $finish. This will report the simulation time, location, and statistics about the memory and CPU time used in simulation if the simulator is following the standard. With the provided example using ModelSim 10.1d, all combinations reported the same memory usage. Run time was only effected by the number of calls the print method, not the const/static attribute. If I had to guess, the performance would be (ordered best to worse): const string in a static method string in a static method const static string static string const string string
Instrumenting bytecode at method level
async_work_group_copy from __constant
How to use Pascal Inno Setup ExpandConstant with a string variable?
Why are constants in C-header files of libraries always defined as hexadecimal?
DirectX11 set shader constants
wampserver configuration - how to enable constants?
How do I use a constant to specify a File path in NSIS?
What ID values are constant to all Sitecore installations?
Php Notice: Use of undefined constant
fcntl.h doesn't contain all status flag constants
Choosing values for constants
How to manage Constants in Application
PHP Magic Constants
Using constants for message keys and database table names and column names
Why do we always declare constants to be powers of 2?
Weird constants [closed]