Browse Source

Test roundtrip times for parser and formatter. Can optimize now

git-svn-id: https://bucket.mit.edu/svn/nilm/nilmdb@10990 ddd99763-3ecb-0310-9145-efcb8ce7c51f
tags/bxinterval-last
Jim Paris 11 years ago
parent
commit
cb7c0cf83e
2 changed files with 40 additions and 3 deletions
  1. +1
    -1
      setup.cfg
  2. +39
    -2
      tests/test_layout.py

+ 1
- 1
setup.cfg View File

@@ -11,7 +11,7 @@ cover-erase=
stop= stop=
verbosity=2 verbosity=2
#tests=tests/test_cmdline.py #tests=tests/test_cmdline.py
#tests=tests/test_layout.py
tests=tests/test_layout.py
#tests=tests/test_interval.py #tests=tests/test_interval.py
#tests=tests/test_client.py #tests=tests/test_client.py
#tests=tests/test_timestamper.py #tests=tests/test_timestamper.py


+ 39
- 2
tests/test_layout.py View File

@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

import nilmdb import nilmdb


from nilmdb.printf import * from nilmdb.printf import *
@@ -205,6 +207,41 @@ class TestLayouts(object):
do_roundtrip(name_rawnotch, datagen) do_roundtrip(name_rawnotch, datagen)


class TestLayoutSpeed: class TestLayoutSpeed:
@unittest.skip("this is slow")
#@unittest.skip("this is slow")
def test_layout_speed(self): def test_layout_speed(self):
pass
import time

random.seed(54321)

def do_speedtest(layout, datagen, rows = 5000, times = 100):
# Build data once
data = ""
ts = 1234567890
for r in range(rows):
ts += random.uniform(0,1)
row = sprintf("%f", ts) + " "
row += " ".join(datagen())
row += "\n"
data += row

# Do lots of roundtrips
start = time.time()
for i in range(times):
parser = Parser(layout)
formatter = Formatter(layout)
parser.parse(data)
data = formatter.format(parser.data)
elapsed = int((time.time() - start) * 1000)
printf("roundtrip %s: %d ms, %.1f μs/row\n",
layout, elapsed, (1000.0 * elapsed) / (rows * times))

print ""
def datagen():
return [ sprintf("%f", random.uniform(-1000,1000))
for x in range(10) ]
do_speedtest("float32_10", datagen)

def datagen():
return [ sprintf("%d", random.randint(0,65535))
for x in range(10) ]
do_speedtest("uint16_10", datagen)

Loading…
Cancel
Save