<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://olddev.minetest.org/index.php?action=history&amp;feed=atom&amp;title=Minetest.get_us_time</id>
	<title>Minetest.get us time - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://olddev.minetest.org/index.php?action=history&amp;feed=atom&amp;title=Minetest.get_us_time"/>
	<link rel="alternate" type="text/html" href="https://olddev.minetest.org/index.php?title=Minetest.get_us_time&amp;action=history"/>
	<updated>2026-04-15T17:44:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.7</generator>
	<entry>
		<id>https://olddev.minetest.org/index.php?title=Minetest.get_us_time&amp;diff=234&amp;oldid=prev</id>
		<title>&gt;ROllerozxa at 14:00, 25 October 2022</title>
		<link rel="alternate" type="text/html" href="https://olddev.minetest.org/index.php?title=Minetest.get_us_time&amp;diff=234&amp;oldid=prev"/>
		<updated>2022-10-25T14:00:25Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{UnofficialLua}}&lt;br /&gt;
{{DISPLAYTITLE:minetest.get_us_time}}&lt;br /&gt;
&lt;br /&gt;
Returns system time with microsecond precision. For example, it can be useful for profiling mod performance.&amp;lt;br/&amp;gt;&lt;br /&gt;
According to the benchmark test (see below) it works about twice as fast as os.clock.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
local t0_us = minetest.get_us_time();&lt;br /&gt;
-- ...&lt;br /&gt;
local t1_us = minetest.get_us_time();&lt;br /&gt;
local elapsed_time_in_seconds = (t1_us - t0_us)/1000000.0;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
to get time differences, minetest.get_us_time seems to works faster than os.clock:&lt;br /&gt;
&amp;lt;source&amp;gt;[…]&lt;br /&gt;
&lt;br /&gt;
local oclock = os.clock&lt;br /&gt;
local ustime = minetest.get_us_time&lt;br /&gt;
&lt;br /&gt;
local function test_os_clock()&lt;br /&gt;
	local t1 = oclock()&lt;br /&gt;
	local delay = tonumber(oclock() - t1)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function test_get_us_time()&lt;br /&gt;
	local t1 = ustime()&lt;br /&gt;
	local delay = (ustime() - t1) / 1000000&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function apply_timer_tests()&lt;br /&gt;
	local oclock_count = benchmark_function(test_os_clock)&lt;br /&gt;
	local ustime_count = benchmark_function(test_get_us_time)&lt;br /&gt;
	print(&amp;quot;test_os_clock: &amp;quot; .. oclock_count .. &amp;quot; s⁻¹&amp;quot;)&lt;br /&gt;
	print(&amp;quot;test_get_us_time: &amp;quot; .. ustime_count .. &amp;quot; s⁻¹&amp;quot;)&lt;br /&gt;
	print(&amp;quot;minetest.get_us_time is &amp;quot; .. ustime_count / oclock_count .. &amp;quot; times as fast as os.clock&amp;quot;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
apply_timer_tests()&lt;br /&gt;
&lt;br /&gt;
minetest.register_node(&amp;quot;:mo:timtest&amp;quot;, {&lt;br /&gt;
	on_place = apply_timer_tests&lt;br /&gt;
})&lt;br /&gt;
&lt;br /&gt;
--[[ results:&lt;br /&gt;
&lt;br /&gt;
Using minetest.get_us_time for measuring (see the benchmark function):&lt;br /&gt;
&lt;br /&gt;
executing when loading:&lt;br /&gt;
&lt;br /&gt;
test_os_clock: 1019720 s⁻¹&lt;br /&gt;
test_get_us_time: 1843077.3333333 s⁻¹&lt;br /&gt;
minetest.get_us_time is 1.8074347206423 times as fast as os.clock&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
placing the node:&lt;br /&gt;
&lt;br /&gt;
test_os_clock: 742641.66666667 s⁻¹&lt;br /&gt;
test_get_us_time: 1772569.6666667 s⁻¹&lt;br /&gt;
minetest.get_us_time is 2.3868438120673 times as fast as os.clock&lt;br /&gt;
&lt;br /&gt;
test_os_clock: 824095 s⁻¹&lt;br /&gt;
test_get_us_time: 1790176.6666667 s⁻¹&lt;br /&gt;
minetest.get_us_time is 2.1722940518589 times as fast as os.clock&lt;br /&gt;
&lt;br /&gt;
test_os_clock: 736386.33333333 s⁻¹&lt;br /&gt;
test_get_us_time: 1769226.6666667 s⁻¹&lt;br /&gt;
minetest.get_us_time is 2.4025794431275 times as fast as os.clock&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Using os.clock for measuring:&lt;br /&gt;
&lt;br /&gt;
executing when loading:&lt;br /&gt;
&lt;br /&gt;
test_os_clock: 801913.66666667 s⁻¹&lt;br /&gt;
test_get_us_time: 1229572.3333333 s⁻¹&lt;br /&gt;
minetest.get_us_time is 1.5332976409347 times as fast as os.clock&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
placing the node:&lt;br /&gt;
&lt;br /&gt;
test_os_clock: 326955 s⁻¹&lt;br /&gt;
test_get_us_time: 642647.66666667 s⁻¹&lt;br /&gt;
minetest.get_us_time is 1.9655538733669 times as fast as os.clock&lt;br /&gt;
&lt;br /&gt;
test_os_clock: 475252 s⁻¹&lt;br /&gt;
test_get_us_time: 844550.33333333 s⁻¹&lt;br /&gt;
minetest.get_us_time is 1.7770579257601 times as fast as os.clock&lt;br /&gt;
&lt;br /&gt;
test_os_clock: 296636 s⁻¹&lt;br /&gt;
test_get_us_time: 574708.33333333 s⁻¹&lt;br /&gt;
minetest.get_us_time is 1.9374193736881 times as fast as os.clock&lt;br /&gt;
]]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
benchmark_function from [[Lua_Optimization_Tips#Benchmarking]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Methods|g]]&lt;/div&gt;</summary>
		<author><name>&gt;ROllerozxa</name></author>
	</entry>
</feed>