Get Time Elapsed In "ms" Format

  1. What do you want to achieve?
    So I want to make a elapsed time using the calculation of “ms”.
  2. What is the issue?
    An example below.

As you can see the whole loading session process is printed and I need to know how to do I get the “Time Elapsed: 123 ms”. Any help is appreciated!

p/s: If you know how to get the total weight and weight buffer, tell me. But of course this is optional, I just curious about this.

The script would look something like this:

-- Start of script
local StartTime = os.time()

--[[ Main Script Here ]]--

-- After everything is done loading
local TimeElapsed = (os.time() - StartTime)*1000 - This is to get ms instead of seconds 
print("Loaded in "..TimeElsapsed.." ms")
3 Likes

It should be

(os.time() - StartTime) * 1000

Because 1 second is 1000 milliseconds;

The original one will give 0.001ms but the one I gave will give 1000ms, as it should.

2 Likes

Thank you, I nearly missed that. Not sure why I didn’t times it by 1000 but good catch! I updated the previous reply.

2 Likes

So your code is working but I realised that the code is only printing (example) 1000 instead of 1234.

So is it possible to make it more like the example I showed just now? (or a more accurate number)

Can you show your code?

The code is exactly the same as the one up there

Try changing os.time() to tick(), os.time is only precise to the second, while tick is precise to decimals.

1 Like

os.clock() is better. time() is better for performance with the cost of negligible accuracy. Also tick() is getting deprecated, although it doesn’t mean it won’t work, it means that there is something better.

3 Likes