diff options
-rw-r--r-- | Makefile.am | 5 | ||||
-rwxr-xr-x | tools/average | 26 | ||||
-rwxr-xr-x | tools/confirm.py | 57 | ||||
-rwxr-xr-x | tools/push | 11 | ||||
-rwxr-xr-x | tools/regtest | 27 | ||||
-rwxr-xr-x | tools/runtests.py | 183 | ||||
-rw-r--r-- | tools/sample.py | 7 | ||||
-rwxr-xr-x | tools/speedcmp | 18 | ||||
-rw-r--r-- | tools/template.h | 248 | ||||
-rw-r--r-- | tools/transfer.dat | 220 |
10 files changed, 802 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index 859ed24c..d1ad82d5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -548,4 +548,9 @@ release: copy-sources release-distcheck: copy-sources (cd $(STAGING); ./acprep --release --build -j3 distcheck) +benchmark: copy-sources + (cd $(STAGING); ./acprep --release --opt --build -j3 all) + PATH=$(PATH):$(srcdir)/tools \ + $(srcdir)/tools/speedcmp 50 $(STAGING)/ledger + # Makefile.am ends here diff --git a/tools/average b/tools/average new file mode 100755 index 00000000..0e95c1c5 --- /dev/null +++ b/tools/average @@ -0,0 +1,26 @@ +#!/usr/bin/python + +import getopt +import time +import string +import sys +import os + +count = 10 + +opts, args = getopt.getopt(sys.argv[1:], "n:") +for opt in opts: + if opt[0] == "-n": + count = int(opt[1]) + +length = 0.0 + +i = 0 +while i < count: + begin = time.time() + cmd = '"' + string.join(args, '" "') + '"'; + os.system(cmd) + length += time.time() - begin + i += 1 + +print >> sys.stderr, length / count diff --git a/tools/confirm.py b/tools/confirm.py new file mode 100755 index 00000000..fa650074 --- /dev/null +++ b/tools/confirm.py @@ -0,0 +1,57 @@ +#!/usr/bin/python + +# This script confirms what ledger tells you. + +import sys +import os +import re + +def clean(num): + return float(re.sub("(\s+|\$|,)","", num)) + +running_total = 0.0 +index = 1 +last_line = "" +errors = 0 + +report = sys.argv[1] +for line in os.popen("./ledger -f tools/standard.dat -e 2004/4 %s reg %s" % + (report, sys.argv[2])): + match = re.match("\\s*([-$,0-9.]+)\\s+([-$,0-9.]+)", line[55:]) + if not match: + continue + value = clean(match.group(1)) + total = clean(match.group(2)) + + running_total += value + diff = abs(running_total - total) + if report == "-V" or report == "-G" and diff < 0.015: + diff = 0.0 + if diff > 0.001: + print "! discrepancy of %.2f (%.2f - %.2f) at line %d:" % \ + (running_total - total, running_total, total, index) + print line, + running_total = total + errors += 1 + + index += 1 + last_line = line + +balance_total = 0.0 + +for line in os.popen("./ledger -f tools/standard.dat -e 2004/4 %s bal %s" % + (report, sys.argv[2])): + if line[0] != '-': + balance_total = clean(line[:20]) + +diff = abs(balance_total - running_total) +if report == "-V" or report == "-G" and diff < 0.015: + diff = 0.0 +if diff > 0.001: + print + print "! discrepancy of %.2f (%.2f - %.2f) between register and balance" % \ + (balance_total - running_total, balance_total, running_total) + print last_line, + errors += 1 + +sys.exit(errors) diff --git a/tools/push b/tools/push new file mode 100755 index 00000000..5bb95fb6 --- /dev/null +++ b/tools/push @@ -0,0 +1,11 @@ +#!/bin/sh + +git push origin +git push --tags origin + +git push mirror +git push --tags mirror + +git remote update + +github network fetch diff --git a/tools/regtest b/tools/regtest new file mode 100755 index 00000000..6a59c39f --- /dev/null +++ b/tools/regtest @@ -0,0 +1,27 @@ +#!/bin/sh + +errors=0 + +if [ ! -f tools/standard.dat ]; then + exit 0 +fi + +for test in \ + "-O nrl:checking" \ + "-O ^expenses" \ + "-B 401" \ + "-V 401" \ + "-G 401" \ + "-B ira" \ + "-V ira" \ + "-G ira" \ + "-B retire" \ + "-V retire" \ + "-G retire" +do + echo testing: $test + python tests/confirm.py $test + errors=`expr $errors + $?` +done + +exit $errors diff --git a/tools/runtests.py b/tools/runtests.py new file mode 100755 index 00000000..b242fa6d --- /dev/null +++ b/tools/runtests.py @@ -0,0 +1,183 @@ +#!/usr/bin/env python + +import random +import string +import signal +import os +import sys + +true, false = 1, 0 + +options = [ + "--account=TempAccount", + "--actual", + "--add-budget", + "--amount-data", + "--amount=a", + "--ansi", + "--ansi-invert", + "--average", + #"--balance-format", + "--basis", + "--begin=2004/01", + "--budget", + "--by-payee", + #"--cache=/tmp/cache", + "--cleared", + "--collapse", + "--comm-as-payee", + #"--csv-register-format", + "--current", + "--date-format=%Y", + "--descend='$100'", + "--descend-if='t=={$100}'", + "--deviation", + "--display='a>10'", + "--dow", + "--download", + "--effective", + "--empty", + "--end=2005/01", + #"--equity-format", + #"--file=/tmp/file", + "--forecast='d<[2006]'", + "--format=%Y", + #"--full-help", + "--gain", + "--head=10", + #"--help", + #"--help-calc", + #"--help-comm", + #"--help-disp", + #"--init-file=/tmp/init", + #"--input-date-format", + "--limit='a>10'", + "--lots", + "--lot-prices", + "--lot-dates", + "--lot-tags", + "--market", + "--monthly", + "--no-cache", + #"--output=/tmp/output", + #"--pager", + #"--percentage", + "--performance", + "--period-sort=A\\(t\\)", + "--period=oct", + #"--plot-amount-format", + #"--plot-total-format", + "--price", + "--price-exp=1000", + #"--price-db=/tmp/foo", + #"--prices-format", + #"--print-format", + "--quantity", + "--real", + #"--reconcile", + #"--reconcile-date", + #"--register-format", + "--related", + "--sort=A\\(t\\)", + "--subtotal", + "--tail=5", + "--total-data", + "--total=O", + "--totals", + "--unbudgeted", + "--uncleared", + #"--version", + "--weekly", + "--wide", + #"--wide-register-format", + #"--write-hdr-format", + #"--write-xact-format", + "--yearly", +] + +commands = [ + "bal rent", + "bal ira", + "bal auto", + "reg rent", + "reg ira", + "reg expenses:food", + "print rent", + "print irc", + "xml rent", + "xml irc", + "equity rent", + "equity ira", + "prices AAPL", +] + +random.seed () + +loop = true +count = 0 +errors = 0 +if len(sys.argv) > 1: + errors = int(sys.argv[1]) +signals = 0 + +while loop: + try: + n = random.randint (0, len (options)) + opts = random.sample (options, n) + for cmd in commands: + if os.path.exists ("/tmp/out"): + os.unlink ("/tmp/out") + + cmd = "./ledger -f tools/standard.dat " + string.join(opts, " ") + " " + cmd + \ + " >> /tmp/out 2>&1" + + sys.stdout = open ("/tmp/out", "w") + print "::", cmd + sys.stdout.close () + + ret = os.system (cmd) + + sys.stdout = open ("/tmp/out", "a") + + # Convert an odd UNIX return type into the appropriate + # signal indication. + if ret and ret % 256 == 0 and ret / 256 > 127: + ret = 0x100 + (ret / 256 - 128) + + if ret and ret % 256 == 0: + print "ERROR: Return value", ret / 256 + sys.stdout.close () + os.system ("cat /tmp/out >> errors.out") + errors += 1 + elif ret: + if ret % 256 == signal.SIGINT: + loop = false + break + print "SIGNAL: Return value", ret % 256 + sys.stdout.close () + os.system ("cat /tmp/out >> signals.out") + signals += 1 + else: + sys.stdout.close () + os.system ("cat /tmp/out >> results.out") + + sys.stdout = sys.__stdout__ + count += 1 + if count < 10 or \ + (count < 100 and count % 10 == 0) or \ + (count < 1000 and count % 100 == 0) or \ + count % 1000 == 0: + if signals > 0 and errors > 0: + print "%d tests ... (%d signals, %d errors)" % \ + (count, signals, errors) + elif signals > 0: + print "%d tests ... (%d signals)" % \ + (count, signals) + elif errors > 0: + print "%d tests ... (%d errors)" % \ + (count, errors) + else: + print "%d tests ..." % count + + except KeyboardInterrupt: + loop = false diff --git a/tools/sample.py b/tools/sample.py new file mode 100644 index 00000000..e32ebbcd --- /dev/null +++ b/tools/sample.py @@ -0,0 +1,7 @@ +import ledger + +def myvalue(incoming): + x = ledger.Amount("$123.12") + print x + print x * 1 + return x * 1 diff --git a/tools/speedcmp b/tools/speedcmp new file mode 100755 index 00000000..a040724e --- /dev/null +++ b/tools/speedcmp @@ -0,0 +1,18 @@ +#!/bin/sh + +# ex: speedcmp ledger ledger-2.4 50 + +export LEDGER_FILE=$PWD/tools/temp.dat +export LEDGER_CACHE=$PWD/tools/temp.cache + +count=$1 +shift 1 + +for i in "$@"; do + echo -n "textual $i: " + average -n $count $i -o /dev/null -f $LEDGER reg rent + + rm -f $LEDGER_CACHE; $i -o /dev/null reg rent > /dev/null 2>&1 + echo -n "binary $i: " + average -n $count $i -o /dev/null reg rent +done diff --git a/tools/template.h b/tools/template.h new file mode 100644 index 00000000..ce55cf02 --- /dev/null +++ b/tools/template.h @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2003-2009, John Wiegley. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of New Artisans LLC nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup the_group Group Title + * @addtogroup the_group + */ + +/** + * @file template.h + * @author John Wiegley + * + * @ingroup the_group + * + * @brief Brief description + * + * Full description. + */ +#ifndef _TEMPLATE_H +#define _TEMPLATE_H + +namespace template { + +/** + * @brief Brief description + * + * Full description. + */ +class template_t : public ordered_field_operators<template_t> +#if 0 + public boost::noncopyable +#endif +{ +public: + /** + * @name Class statics + */ + /*@{*/ + + static bool stream_fullstrings; + + /*@}*/ + + /** + * @name Constructors + */ + /*@{*/ + + /** + * @see other_function + * @warning Watch out! + */ + template_t() { + TRACE_CTOR(template_t, ""); + } + + /*@}*/ + + /** + * @name Destructor + */ + /*@{*/ + + ~template_t() { + TRACE_DTOR(template_t); + } + + /*@}*/ + + /** + * @name Assignment and copy + */ + /*@{*/ + + template_t(const template_t& other) { + TRACE_CTOR(template_t, "copy"); + } + + template_t& operator=(const template_t& other); + + /*@}*/ + +private: + template_t(const template_t& other); + +public: + /** + * @name Comparison + */ + /*@{*/ + + /** + * Compare two template objects. + * @param other + * @return An integer <0, 0 or >0. + */ + int compare(const template_t& other) const; + + template <typename T> + bool operator==(const T& val) const { + return compare(val) == 0; + } + template <typename T> + bool operator<(const T& other) const { + return compare(other) < 0; + } + template <typename T> + bool operator>(const T& other) const { + return compare(other) > 0; + } + + /*@}*/ + + /** + * @name Binary arithmetic + */ + /*@{*/ + + template_t& operator+=(const template_t& other); + template_t& operator-=(const template_t& other); + template_t& operator*=(const template_t& other); + template_t& operator/=(const template_t& other); + + /*@}*/ + + /** + * @name Unary arithmetic + */ + /*@{*/ + + template_t operator-() const { + return template_t(); + } + + /*@}*/ + + /** + * @name Truth tests + */ + /*@{*/ + + operator bool() const { + return false; + } + + /*@}*/ + + /** + * @name Conversion + */ + /*@{*/ + + operator int() const { + return 0; + } + + /*@}*/ + + /** + * @name Parsing + */ + /*@{*/ + + bool parse(std::istream& in); + bool parse(const string& str) { + std::istringstream stream(str); + bool result = parse(stream, flags); + assert(stream.eof()); + return result; + } + + /*@}*/ + + /** + * @name Printing + */ + /*@{*/ + + void print(std::ostream& out) const; + + /*@}*/ + + /** + * @name Serialization + */ + /*@{*/ + + void read(std::istream& in); + void read(const char *& data); + void write(std::ostream& out) const; + + /*@}*/ + + /** + * @name XML Serialization + */ + /*@{*/ + + void read_xml(std::istream& in); + void write_xml(std::ostream& out, const int depth = 0) const; + + /*@}*/ + + /** + * @name Debugging + */ + /*@{*/ + + void dump(std::ostream& out) const { + print(out); + } + + bool valid() const; + + /*@}*/ +}; + +} // namespace template + +#endif // _TEMPLATE_H diff --git a/tools/transfer.dat b/tools/transfer.dat new file mode 100644 index 00000000..1e2991dc --- /dev/null +++ b/tools/transfer.dat @@ -0,0 +1,220 @@ +2004/08/02 Transfer to hcoop.net + Expenses:Internet 59820 bytes + Liabilities:Payable:hcoop.net + +2004/08/02 Transfer to hcoop.net + Expenses:Internet 58626 bytes + Liabilities:Payable:hcoop.net + +2004/08/02 Transfer to hcoop.net + Expenses:Internet 2997279 bytes + Liabilities:Payable:hcoop.net + +2004/08/03 Transfer to hcoop.net + Expenses:Internet 227266 bytes + Liabilities:Payable:hcoop.net + +2004/08/03 Transfer to hcoop.net + Expenses:Internet 54375 bytes + Liabilities:Payable:hcoop.net + +2004/08/05 Transfer to hcoop.net + Expenses:Internet 54353 bytes + Liabilities:Payable:hcoop.net + +2004/08/07 Transfer to hcoop.net + Expenses:Internet 54353 bytes + Liabilities:Payable:hcoop.net + +2004/08/16 Transfer to hcoop.net + Expenses:Internet 54353 bytes + Liabilities:Payable:hcoop.net + +2004/08/20 Transfer to hcoop.net + Expenses:Internet 133967 bytes + Liabilities:Payable:hcoop.net + +2004/08/20 Transfer to hcoop.net + Expenses:Internet 124438 bytes + Liabilities:Payable:hcoop.net + +2004/08/21 Transfer to hcoop.net + Expenses:Internet 148691 bytes + Liabilities:Payable:hcoop.net + +2004/08/22 Transfer to hcoop.net + Expenses:Internet 660168 bytes + Liabilities:Payable:hcoop.net + +2004/08/22 Transfer to hcoop.net + Expenses:Internet 2876287 bytes + Liabilities:Payable:hcoop.net + +2004/08/24 Transfer to hcoop.net + Expenses:Internet 55166 bytes + Liabilities:Payable:hcoop.net + +2004/08/24 Transfer to hcoop.net + Expenses:Internet 54743 bytes + Liabilities:Payable:hcoop.net + +2004/08/28 Transfer to hcoop.net + Expenses:Internet 2414720 bytes + Liabilities:Payable:hcoop.net + +2004/08/30 Transfer to hcoop.net + Expenses:Internet 396873 bytes + Liabilities:Payable:hcoop.net + +2004/08/30 Transfer to hcoop.net + Expenses:Internet 2482301 bytes + Liabilities:Payable:hcoop.net + +2004/08/31 Transfer to hcoop.net + Expenses:Internet 3696731 bytes + Liabilities:Payable:hcoop.net + +2004/09/01 Transfer to hcoop.net + Expenses:Internet 2748364 bytes + Liabilities:Payable:hcoop.net + +2004/09/05 Transfer to hcoop.net + Expenses:Internet 2500517 bytes + Liabilities:Payable:hcoop.net + +2004/09/06 Transfer to hcoop.net + Expenses:Internet 54910 bytes + Liabilities:Payable:hcoop.net + +2004/09/06 Transfer to hcoop.net + Expenses:Internet 9196055 bytes + Liabilities:Payable:hcoop.net + +2004/09/07 Transfer to hcoop.net + Expenses:Internet 2640950 bytes + Liabilities:Payable:hcoop.net + +2004/09/07 Transfer to hcoop.net + Expenses:Internet 94442 bytes + Liabilities:Payable:hcoop.net + +2004/09/08 Transfer to hcoop.net + Expenses:Internet 2579158 bytes + Liabilities:Payable:hcoop.net + +2004/09/08 Transfer to hcoop.net + Expenses:Internet 530904 bytes + Liabilities:Payable:hcoop.net + +2004/09/08 Transfer to hcoop.net + Expenses:Internet 27368 bytes + Liabilities:Payable:hcoop.net + +2004/09/08 Transfer to hcoop.net + Expenses:Internet 6593 bytes + Liabilities:Payable:hcoop.net + +2004/09/08 Transfer to hcoop.net + Expenses:Internet 279 bytes + Liabilities:Payable:hcoop.net + +2004/09/08 Transfer to hcoop.net + Expenses:Internet 773 bytes + Liabilities:Payable:hcoop.net + +2004/09/09 Transfer to hcoop.net + Expenses:Internet 4217461 bytes + Liabilities:Payable:hcoop.net + +2004/09/10 Transfer to hcoop.net + Expenses:Internet 100241 bytes + Liabilities:Payable:hcoop.net + +2004/09/10 Transfer to hcoop.net + Expenses:Internet 117866 bytes + Liabilities:Payable:hcoop.net + +2004/09/10 Transfer to hcoop.net + Expenses:Internet 111275 bytes + Liabilities:Payable:hcoop.net + +2004/09/11 Transfer to hcoop.net + Expenses:Internet 2717020 bytes + Liabilities:Payable:hcoop.net + +2004/09/12 Transfer to hcoop.net + Expenses:Internet 88188 bytes + Liabilities:Payable:hcoop.net + +2004/09/13 Transfer to hcoop.net + Expenses:Internet 3046553 bytes + Liabilities:Payable:hcoop.net + +2004/09/13 Transfer to hcoop.net + Expenses:Internet 3370971 bytes + Liabilities:Payable:hcoop.net + +2004/09/13 Transfer to hcoop.net + Expenses:Internet 2941407 bytes + Liabilities:Payable:hcoop.net + +2004/09/13 Transfer to hcoop.net + Expenses:Internet 2101943 bytes + Liabilities:Payable:hcoop.net + +2004/09/15 Transfer to hcoop.net + Expenses:Internet 3050131 bytes + Liabilities:Payable:hcoop.net + +2004/09/15 Transfer to hcoop.net + Expenses:Internet 2638687 bytes + Liabilities:Payable:hcoop.net + +2004/09/15 Transfer to hcoop.net + Expenses:Internet 2668178 bytes + Liabilities:Payable:hcoop.net + +2004/09/16 Transfer to hcoop.net + Expenses:Internet 2645212 bytes + Liabilities:Payable:hcoop.net + +2004/09/17 Transfer to hcoop.net + Expenses:Internet 336579 bytes + Liabilities:Payable:hcoop.net + +2004/09/17 Transfer to hcoop.net + Expenses:Internet 104305 bytes + Liabilities:Payable:hcoop.net + +2004/09/18 Transfer to hcoop.net + Expenses:Internet 3117533 bytes + Liabilities:Payable:hcoop.net + +2004/09/19 Transfer to hcoop.net + Expenses:Internet 120777 bytes + Liabilities:Payable:hcoop.net + +2004/09/20 Transfer to hcoop.net + Expenses:Internet 193151 bytes + Liabilities:Payable:hcoop.net + +2004/09/20 Transfer to hcoop.net + Expenses:Internet 56204 bytes + Liabilities:Payable:hcoop.net + +2004/09/21 Transfer to hcoop.net + Expenses:Internet 315126 bytes + Liabilities:Payable:hcoop.net + +2004/09/22 Transfer to hcoop.net + Expenses:Internet 138076 bytes + Liabilities:Payable:hcoop.net + +2004/09/24 Transfer to hcoop.net + Expenses:Internet 817190 bytes + Liabilities:Payable:hcoop.net + +2004/10/05 Transfer to hcoop.net + Expenses:Internet 356104 bytes + Liabilities:Payable:hcoop.net + |