From 31ecb9abcdfea2e2f559a7fe15d64458e5c0a901 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 2 Dec 2018 18:08:48 +0100 Subject: add timing and compression ratio --- tests/tgziplike.nim | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/tgziplike.nim b/tests/tgziplike.nim index 2b79240..836e4be 100644 --- a/tests/tgziplike.nim +++ b/tests/tgziplike.nim @@ -14,27 +14,27 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import unittest, os, ospaths, osproc +import unittest, os, ospaths, osproc, times import gziplike -const tempDir = "tmp" - suite "main": + const tempDir = "tmp" + + proc testIdentity(input: string, intermediate = tempDir / "compressed", final = tempDir / "decompressed"): bool = + let compressionStartTime = getTime() + compress.transform(input, intermediate) + echo("compression done in ", getTime() - compressionStartTime) + echo("compression ratio: ", (intermediate.getFileSize() * 100) div input.getFileSize(), "%") + let decompressionStartTime = getTime() + decompress.transform(intermediate, final) + echo("decompression done in ", getTime() - decompressionStartTime) + startProcess("cmp", args=[input, final], options={poUsePath}).waitForExit() == 0 + setup: createDir(tempDir) teardown: removeDir(tempDir) test "identity (text)": - let input = "license.md" - let intermediate = tempDir / "compressed" - let final = tempDir / "decompressed" - compress.transform(input, intermediate) - decompress.transform(intermediate, final) - check startProcess("cmp", args=[input, final], options={poUsePath}).waitForExit() == 0 + check testIdentity("license.md") test "identity (binary)": - let input = "tests" / "tgziplike" - let intermediate = tempDir / "compressed" - let final = tempDir / "decompressed" - compress.transform(input, intermediate) - decompress.transform(intermediate, final) - check startProcess("cmp", args=[input, final], options={poUsePath}).waitForExit() == 0 + check testIdentity("tests" / "tgziplike") -- cgit v1.2.3