From 97e16d7380ef79a799eed2116e471643584f2edd Mon Sep 17 00:00:00 2001 From: Leslie Krause Date: Fri, 24 Aug 2018 17:14:35 -0400 Subject: [PATCH] Build 02 - included mod.conf and description.txt files - included working code examples for developers - implemented stack for non-linear testing of code --- README.txt | 13 ++++++++++++- description.txt | 3 +++ example.lua | 17 +++++++++++++++++ init.lua | 16 +++++++--------- mod.conf | 4 ++++ 5 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 description.txt create mode 100644 example.lua create mode 100644 mod.conf diff --git a/README.txt b/README.txt index 64be2f3..009de7d 100644 --- a/README.txt +++ b/README.txt @@ -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 ---------------------- diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..ed6701f --- /dev/null +++ b/description.txt @@ -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 diff --git a/example.lua b/example.lua new file mode 100644 index 0000000..9310ace --- /dev/null +++ b/example.lua @@ -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_( ) diff --git a/init.lua b/init.lua index 74fd39c..e4a7c74 100644 --- a/init.lua +++ b/init.lua @@ -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 ) ) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..ea89145 --- /dev/null +++ b/mod.conf @@ -0,0 +1,4 @@ +name = stopwatch +title = Stopwatch +author = sorcerykid +license = MIT