lr_save_timestamp Function in LoadRunner

This function is not frequently used in LoadRunner. But in some situations, it is very helpful where we need timestamp for any request in performance testing. Here we need to understand what is timestamp all about. Timestamp is nothing but it is the number of milliseconds since midnight January 1st, 1970 (also known as Unix Epoch). Overall, we can say that it saves the current time in a parameter. Let us see the syntax of this function.

int lr_save_timestamp( const char* tmstampParam, [DIGITS,] LAST );

we can clearly see that this function returns the value of type int. Let us see the arguments which is accepted by this function. An argument may be considered as input, which is accepted by the function. This function returns LR_PASS (0) when it is successful, otherwise, it returns none zero value when it is unsuccessful.

tmstampParam it the name of the parameter which is used to store the timestamp.

DIGITS 

It is an optional parameter. We may or may not include it as a function parameter depending on the requirement. The default is 13. With DIGITS=13, We will get 13 digit time elapsed since epoch and one more thing to be noted here is that the last 3 digits will indicate milliseconds which adds more Precision to the measurement.

one thing to keep in mind is that lr_save_timestamp saves the current local timestamp of the computer where we are running the script.Returns LR_PASS (0) on success. Non-zero return value indicates failure.

In the following example, we have taken the timestamp with default value of 13 digits in which the last three digits will return time in milliseconds. Following is the sample code.

   lr_save_timestamp(“param”, LAST );

   lr_output_message(lr_eval_string(“{param}”));

let us see how it looks in LoadRunner window.

lr_save_timestamp

The output of the above executed script is given as below. We can clearly see that output is in 13 digits out of which the last three digits are in milliseconds.

Starting action Action.

Action.c(4): 1586522023175

Ending action Action.

Let us see the output in the log window of LoadRunner in the form of a screenshot given below.

lr_save_timestamp Outputs Timestamp

In the following example, the timestamp is saved and a length of 10 digits is specified – the epoch time in seconds and will be no time in milliseconds. Let us see the sample code as given below.

   lr_save_timestamp(“param”, “DIGITS=10”, LAST );

   lr_output_message(lr_eval_string(“{param}”));

let us see how it looks in LoadRunner window.

lr_save_timestamp with example

Output of the above executed script is given as below. We can clearly see that output of the above executed script consists of 10 digits, which represents the time elapsed since epoch in seconds.

Starting action Action.

Action.c(5): 1586527974

Ending action Action.

We can see see the same in the output log window of LoadRunner which is given in the form of screenshot given below.

lr_save_timestamp Example2

Overall, we can say that this is a very useful function in LoadRunner which is used for generating timestamp and we also know that we can generate timestamps in different waysand we have to use it wisely to get productive results while preparing performance testing script using LoadRunner.