diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2007-02-08 02:14:23 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2007-02-08 02:14:23 +0000 |
commit | af5c96da10b2ce86c975769a3554ad9557bef431 (patch) | |
tree | 45b90b6b491cdb544fbb2cfe4230b19fc1a077b2 /xdelta3/xdelta3-regtest.py | |
parent | 750fb98f99a96c390a86185383ce1739eadeae0a (diff) |
Python swig module working with xd3_encode_memory(), xd3_decode_memory(),
and xd3_main_cmdline(). module added to xdelta3-regtest.py run-length
experiments. XD3_INVALID_INPUT code added to distinguish decoder errors
from invalid stream-states. xdelta3-test.py unittest added for python
module. xd3_encode_memory() now limits config.winsize to <= 1MB:
xd3_process_memory() now properly splits the input buffer into windows.
Diffstat (limited to 'xdelta3/xdelta3-regtest.py')
-rwxr-xr-x | xdelta3/xdelta3-regtest.py | 58 |
1 files changed, 49 insertions, 9 deletions
diff --git a/xdelta3/xdelta3-regtest.py b/xdelta3/xdelta3-regtest.py index 1b84940..db6f06f 100755 --- a/xdelta3/xdelta3-regtest.py +++ b/xdelta3/xdelta3-regtest.py | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | import os, sys, math, re, time, types, array, random | 26 | import os, sys, math, re, time, types, array, random |
27 | import xdelta3main | 27 | import xdelta3main |
28 | import xdelta3 | ||
28 | 29 | ||
29 | HIST_SIZE = 10 # the number of buckets | 30 | HIST_SIZE = 10 # the number of buckets |
30 | MIN_SIZE = 0 | 31 | MIN_SIZE = 0 |
@@ -497,6 +498,7 @@ class GzipInfo: | |||
497 | 498 | ||
498 | class Xdelta3Info: | 499 | class Xdelta3Info: |
499 | def __init__(self,target,delta): | 500 | def __init__(self,target,delta): |
501 | # TODO: bug is fixed | ||
500 | self.extcomp = 0 # TODO: I removed some code that called printhdr | 502 | self.extcomp = 0 # TODO: I removed some code that called printhdr |
501 | self.hdrsize = 0 # to compute these, but printhdr uses stdout (now) | 503 | self.hdrsize = 0 # to compute these, but printhdr uses stdout (now) |
502 | self.tgtsize = os.stat(target).st_size | 504 | self.tgtsize = os.stat(target).st_size |
@@ -506,6 +508,23 @@ class Xdelta3Info: | |||
506 | else: | 508 | else: |
507 | self.ideal = 0.0 | 509 | self.ideal = 0.0 |
508 | 510 | ||
511 | class Xdelta3ModInfo: | ||
512 | def __init__(self,target,delta): | ||
513 | #tmp = open(DFILE, 'w') | ||
514 | #tmp.write(patch) | ||
515 | #tmp.close() | ||
516 | #r3 = xdelta3.xd3_main_cmdline(['xdelta3', 'printhdr', DFILE, RFILE]) | ||
517 | #if r3 != 0: | ||
518 | # raise CommandError('memory', 'print failed: %s' % r3) | ||
519 | #hdr = open(RFILE, 'r').read() | ||
520 | #print hdr | ||
521 | self.tgtsize = len(target) | ||
522 | self.dsize = len(delta) | ||
523 | if self.tgtsize > 0: | ||
524 | self.ideal = 100.0 * self.dsize / self.tgtsize; | ||
525 | else: | ||
526 | self.ideal = 0.0 | ||
527 | |||
509 | class Xdelta3Pair: | 528 | class Xdelta3Pair: |
510 | def __init__(self): | 529 | def __init__(self): |
511 | self.type = 'xdelta3' | 530 | self.type = 'xdelta3' |
@@ -585,11 +604,27 @@ class Xdelta3Run1: | |||
585 | self.file = file | 604 | self.file = file |
586 | def Run(self,trial): | 605 | def Run(self,trial): |
587 | RunXdelta3(testwide_encode_args + | 606 | RunXdelta3(testwide_encode_args + |
588 | ['-efq', self.file, DFILE]) | 607 | ['-efqW', str(1<<20), self.file, DFILE]) |
589 | if trial > 0: | 608 | if trial > 0: |
590 | return None | 609 | return None |
591 | return Xdelta3Info(self.file,DFILE) | 610 | return Xdelta3Info(self.file,DFILE) |
592 | 611 | ||
612 | class Xdelta3Mod1: | ||
613 | def __init__(self,file): | ||
614 | self.data = open(file, 'r').read() | ||
615 | def Run(self,trial): | ||
616 | r1, patch = xdelta3.xd3_encode_memory(self.data, None, 1000000, 1<<10) | ||
617 | if r1 != 0: | ||
618 | raise CommandError('memory', 'encode failed: %s' % r1) | ||
619 | if trial > 0: | ||
620 | return None | ||
621 | r2, data1 = xdelta3.xd3_decode_memory(patch, None, len(self.data)) | ||
622 | if r2 != 0: | ||
623 | raise CommandError('memory', 'decode failed: %s' % r1) | ||
624 | if self.data != data1: | ||
625 | raise CommandError('memory', 'bad output: %s' % self.data, data1) | ||
626 | return Xdelta3ModInfo(self.data,patch) | ||
627 | |||
593 | class GzipRun1: | 628 | class GzipRun1: |
594 | def __init__(self,file): | 629 | def __init__(self,file): |
595 | self.file = file | 630 | self.file = file |
@@ -608,7 +643,8 @@ def SetFileSize(F,L): | |||
608 | 643 | ||
609 | def ReportSpeed(L,tr,desc): | 644 | def ReportSpeed(L,tr,desc): |
610 | print '%s 0-run length %u: dsize %u: time %.3f ms: encode %.0f B/sec: in %u trials' % \ | 645 | print '%s 0-run length %u: dsize %u: time %.3f ms: encode %.0f B/sec: in %u trials' % \ |
611 | (desc, L, tr.r1.dsize, tr.time.mean * 1000.0, ((L+tr.r1.dsize) / tr.time.mean), tr.trials) | 646 | (desc, L, tr.r1.dsize, tr.time.mean * 1000.0, |
647 | ((L+tr.r1.dsize) / tr.time.mean), tr.trials) | ||
612 | 648 | ||
613 | class RandomTestResult: | 649 | class RandomTestResult: |
614 | def __init__(self, round, config, runtime, compsize): | 650 | def __init__(self, round, config, runtime, compsize): |
@@ -870,10 +906,13 @@ class RandomTester: | |||
870 | #end | 906 | #end |
871 | 907 | ||
872 | def RunSpeed(): | 908 | def RunSpeed(): |
909 | # TODO: Start testing window sizes | ||
873 | for L in Decimals(MAX_RUN): | 910 | for L in Decimals(MAX_RUN): |
874 | SetFileSize(RUNFILE, L) | 911 | SetFileSize(RUNFILE, L) |
875 | trx = TimeRun(Xdelta3Run1(RUNFILE)) | 912 | trx = TimeRun(Xdelta3Run1(RUNFILE)) |
876 | ReportSpeed(L,trx,'xdelta3') | 913 | ReportSpeed(L,trx,'xdelta3') |
914 | trm = TimeRun(Xdelta3Mod1(RUNFILE)) | ||
915 | ReportSpeed(L,trm,'module ') | ||
877 | trg = TimeRun(GzipRun1(RUNFILE)) | 916 | trg = TimeRun(GzipRun1(RUNFILE)) |
878 | ReportSpeed(L,trg,'gzip ') | 917 | ReportSpeed(L,trg,'gzip ') |
879 | #end | 918 | #end |
@@ -886,7 +925,14 @@ if __name__ == "__main__": | |||
886 | #rcsf = Test() | 925 | #rcsf = Test() |
887 | configs = [] | 926 | configs = [] |
888 | 927 | ||
889 | while 1: | 928 | # This tests pairwise (date-ordered) performance |
929 | #rcsf.PairsByDate(Xdelta3Pair()) | ||
930 | |||
931 | # This tests the raw speed of 0-byte inputs | ||
932 | RunSpeed() | ||
933 | |||
934 | |||
935 | while 0: | ||
890 | #f1 = '/tmp/big.1' | 936 | #f1 = '/tmp/big.1' |
891 | #f2 = '/tmp/big.2' | 937 | #f2 = '/tmp/big.2' |
892 | test = RandomTester(configs) | 938 | test = RandomTester(configs) |
@@ -907,12 +953,6 @@ if __name__ == "__main__": | |||
907 | #end | 953 | #end |
908 | #end | 954 | #end |
909 | 955 | ||
910 | # This tests pairwise (date-ordered) performance | ||
911 | #rcsf.PairsByDate(Xdelta3Pair()) | ||
912 | |||
913 | # This tests the raw speed of 0-byte inputs | ||
914 | #RunSpeed() | ||
915 | |||
916 | except CommandError: | 956 | except CommandError: |
917 | pass | 957 | pass |
918 | else: | 958 | else: |