Hi everyone,
One of my tasks is the do the reliability analysis, in which I do using Fit Life by X.
In doing so, I have two JSL scripts that output exactly the same results but have different coding approaches.
The first approach simply has several pieces of code cascading together. The pseudo code looks something like the following:
// Plot Fit Life by X #1
Fit Life by X(...);
// Plot Fit Life by X #2
Fit Life by X(...);
// Plot Fit Life by X #3
Fit Life by X(...);
// And so on
The second one has a single function that we call it repeated with different X, Y, and censor columns. The pseudo code looks something like the following:
// Function that contains Fit Life by X
reli_analysis = function(
{input parameters},
{local variables},
Fit Life by X(...);
);
// Call the above function multiple times
reli_analysis(input parameters set #1);
reli_analysis(input parameters set #2);
reli_analysis(input parameters set #3);
// And so on
What I experienced is that the second code is much faster than the first one, in the order of nearly 10 times faster. (My actual JSL with the real dataset have the execution time (measured through wall clock time) of ~17 seconds from Code #2 vs. ~170 seconds from Code #1)
I have three questions as follows:
1. Why calling the function is much faster than writing out all codes explicitly?
2. What are other practices/tips that I should generally do in order to ensure that my code have the most efficient time and/or space complexity?
3. I am not sure whether JSL has built-in timing functions like CPU time and wall clock time? I timed the code executions by using today() function, but it involves a lot of manual coding. In addition, the elapsed times calculated this way are always slightly different depending on whether there are other tasks being executed.
Thank you so much for your help.
JMP Version: 17.0