- included mod.conf and description.txt files
- included working code examples for developers
- implemented stack for non-linear testing of code
This commit is contained in:
Leslie Krause 2018-08-24 17:14:35 -04:00
parent 16b804f5cd
commit 97e16d7380
5 changed files with 43 additions and 10 deletions

View File

@ -1,4 +1,4 @@
Stopwatch Mod v1.0 Stopwatch Mod v1.1
By Leslie Krause By Leslie Krause
Repository Repository
@ -11,6 +11,17 @@ Download archive:
https://bitbucket.org/sorcerykid/stopwatch/get/master.zip https://bitbucket.org/sorcerykid/stopwatch/get/master.zip
https://bitbucket.org/sorcerykid/stopwatch/get/master.tar.gz https://bitbucket.org/sorcerykid/stopwatch/get/master.tar.gz
Revision History
----------------------
Version 1.0b (22-Aug-2018)
- initial beta version
Version 1.1b (24-Aug-2018)
- included mod.conf and description.txt files
- included working code examples for developers
- implemented stack for non-linear testing of code
Installation Installation
---------------------- ----------------------

3
description.txt Normal file
View File

@ -0,0 +1,3 @@
Stopwatch is a utility for developers to very quickly benchmark portions of Lua code, but without the complexity and overhead of enabling the mod profiler.
For more information: https://forum.minetest.net/viewtopic.php?f=9&t=20699

17
example.lua Normal file
View File

@ -0,0 +1,17 @@
-- measure the performance of table inserts in append vs prepend mode:
local S, S_ = Stopwatch( )
local y = { }
S( "table prepend" )
for x = 0, 5000 do
table.insert( y, 1, x )
end
S_( )
y = { }
S( "table append" )
for x = 0, 5000 do
table.insert( y, x )
end
S_( )

View File

@ -1,8 +1,8 @@
-------------------------------------------------------- --------------------------------------------------------
-- Minetest :: Stopwatch Mod v1.0 (stopwatch) -- Minetest :: Stopwatch Mod v1.1 (stopwatch)
-- --
-- See README.txt for licensing and release notes. -- See README.txt for licensing and release notes.
-- Copyright (c) 2016-2018, Leslie Ellen Krause -- Copyright (c) 2018, Leslie E. Krause
-------------------------------------------------------- --------------------------------------------------------
function Stopwatch( scale ) function Stopwatch( scale )
@ -12,7 +12,7 @@ function Stopwatch( scale )
local factors = { us = 1, ms = 1000, s = 1000000 } local factors = { us = 1, ms = 1000, s = 1000000 }
local origin = getinfo( 2 ).source local origin = getinfo( 2 ).source
local trials = { } local trials = { }
local id local series = { }
if not scale then if not scale then
scale = "ms" scale = "ms"
@ -28,14 +28,12 @@ function Stopwatch( scale )
v = { count = 0, delta_t = 0 } v = { count = 0, delta_t = 0 }
trials[ id ] = v trials[ id ] = v
end end
table.insert( series, id )
v.start = clock( ) v.start = clock( )
end end
local function S_( is_show, desc ) local function S_( is_show )
if not desc and not id then local id = table.remove( series )
local i = getinfo( 2, "lf" ) local v = trials[ id ]
id = tostring( i.func ) .. ", line " .. i.currentline
end
local v = trials[ desc or id ]
local delta = clock( ) - v.start local delta = clock( ) - v.start
if is_show then if is_show then
print( sprintf( "** trial count = %9.3f %s @%s", delta / factors[ scale ], scale, id ) ) print( sprintf( "** trial count = %9.3f %s @%s", delta / factors[ scale ], scale, id ) )

4
mod.conf Normal file
View File

@ -0,0 +1,4 @@
name = stopwatch
title = Stopwatch
author = sorcerykid
license = MIT