- 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
Repository
@ -11,6 +11,17 @@ Download archive:
https://bitbucket.org/sorcerykid/stopwatch/get/master.zip
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
----------------------

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.
-- Copyright (c) 2016-2018, Leslie Ellen Krause
-- Copyright (c) 2018, Leslie E. Krause
--------------------------------------------------------
function Stopwatch( scale )
@ -12,7 +12,7 @@ function Stopwatch( scale )
local factors = { us = 1, ms = 1000, s = 1000000 }
local origin = getinfo( 2 ).source
local trials = { }
local id
local series = { }
if not scale then
scale = "ms"
@ -28,14 +28,12 @@ function Stopwatch( scale )
v = { count = 0, delta_t = 0 }
trials[ id ] = v
end
table.insert( series, id )
v.start = clock( )
end
local function S_( is_show, desc )
if not desc and not id then
local i = getinfo( 2, "lf" )
id = tostring( i.func ) .. ", line " .. i.currentline
end
local v = trials[ desc or id ]
local function S_( is_show )
local id = table.remove( series )
local v = trials[ id ]
local delta = clock( ) - v.start
if is_show then
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