Methods for using millisecond precision time in Lua _lua

Source: Internet
Author: User
Tags lua

Lua's own time functions can only be accurate to seconds.

In order to count the time of millisecond precision, you can use Luasocket. Download Address Http://files.luaforge.net/releases/luasocket/luasocket

When compiling the installation, you may need to specify the LUAINC variable as your LUA path in the config file in the source package root directory.

Copy Code code as follows:

Local socket = require "socket"
Local T0 = Socket.gettime ()
--Do something
Local T1 = Socket.gettime ()
Print ("Used Time:"). T1-t0 ... " MS ")

Update

If the precision requirements do not require a millisecond level, you can use your own OS module. 0.01 seconds with precision

Copy Code code as follows:

Local s = Os.clock ()
Local E = Os.clock ()
Print ("Used Time". E-s ... "seconds")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.