summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3-regtest.py
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/xdelta3-regtest.py')
-rwxr-xr-xxdelta3/xdelta3-regtest.py152
1 files changed, 57 insertions, 95 deletions
diff --git a/xdelta3/xdelta3-regtest.py b/xdelta3/xdelta3-regtest.py
index 03d3a2e..9e90f8b 100755
--- a/xdelta3/xdelta3-regtest.py
+++ b/xdelta3/xdelta3-regtest.py
@@ -31,8 +31,6 @@ MIN_SIZE = 0
31 31
32TIME_TOO_SHORT = 0.050 32TIME_TOO_SHORT = 0.050
33 33
34MIN_REPS = 1
35MAX_REPS = 1
36SKIP_TRIALS = 2 34SKIP_TRIALS = 2
37MIN_TRIALS = 3 35MIN_TRIALS = 3
38MAX_TRIALS = 15 36MAX_TRIALS = 15
@@ -208,13 +206,12 @@ class RcsFile:
208 self.Vstr(v), 206 self.Vstr(v),
209 self.Verf(v+1), 207 self.Verf(v+1),
210 self.Vstr(v+1))) 208 self.Vstr(v+1)))
211 print 'testing %s %s: ideal %.3f%%: time %.7f: in %u/%u trials' % \ 209 print 'testing %s %s: ideal %.3f%%: time %.7f: in %u trials' % \
212 (os.path.basename(self.fname), 210 (os.path.basename(self.fname),
213 self.Vstr(v+1), 211 self.Vstr(v+1),
214 result.r1.ideal, 212 result.r1.ideal,
215 result.time.mean, 213 result.time.mean,
216 result.trials, 214 result.trials)
217 result.reps)
218 ntrials.append(result) 215 ntrials.append(result)
219 216
220 os.remove(self.Verf(self.totrev-1)) 217 os.remove(self.Verf(self.totrev-1))
@@ -316,15 +313,14 @@ class Bucks:
316# 313#
317# 314#
318class TimeRun: 315class TimeRun:
319 def __init__(self,runnable,set_reps=1,reps=MIN_REPS,max_reps=MAX_REPS,\ 316 def __init__(self,runnable,
320 skip_trials=SKIP_TRIALS,min_trials=MIN_TRIALS,max_trials=MAX_TRIALS, \ 317 skip_trials=SKIP_TRIALS,min_trials=MIN_TRIALS,max_trials=MAX_TRIALS,
321 min_stddev_pct=MIN_STDDEV_PCT): 318 min_stddev_pct=MIN_STDDEV_PCT):
322 319
323 min_trials = min(min_trials,max_trials) 320 min_trials = min(min_trials,max_trials)
324 self.trials = 0 321 self.trials = 0
325 self.measured = [] 322 self.measured = []
326 self.r1 = None 323 self.r1 = None
327 self.reps = reps
328 while 1: 324 while 1:
329 try: 325 try:
330 os.remove(DFILE) 326 os.remove(DFILE)
@@ -335,7 +331,7 @@ class TimeRun:
335 start_time = time.time() 331 start_time = time.time()
336 start_clock = time.clock() 332 start_clock = time.clock()
337 333
338 result = runnable.Run(self.trials, self.reps) 334 result = runnable.Run(self.trials)
339 335
340 if self.r1 == None: 336 if self.r1 == None:
341 self.r1 = result 337 self.r1 = result
@@ -343,15 +339,8 @@ class TimeRun:
343 total_clock = (time.clock() - start_clock) 339 total_clock = (time.clock() - start_clock)
344 total_time = (time.time() - start_time) 340 total_time = (time.time() - start_time)
345 341
346 elap_time = max((total_time) / self.reps, 0.000001) 342 elap_time = max((total_time), 0.000001)
347 elap_clock = max((total_clock) / self.reps, 0.000001) 343 elap_clock = max((total_clock), 0.000001)
348
349 #print 'trial: %d' % self.trials
350 if set_reps and runnable.canrep and total_time < TIME_TOO_SHORT and self.reps < max_reps:
351 self.reps = max(self.reps+1,int(self.reps * TIME_TOO_SHORT / total_time))
352 self.reps = min(self.reps,max_reps)
353 #print 'continue: need more reps: %d' % self.reps
354 continue
355 344
356 self.trials = self.trials + 1 345 self.trials = self.trials + 1
357 346
@@ -478,29 +467,37 @@ class Xdelta3Pair:
478 self.newv = newv 467 self.newv = newv
479 return self 468 return self
480 469
481 def Run(self,trial,reps): 470 def Run(self,trial):
482 RunXdelta3(['-P', 471
483 '%d' % reps] + 472 # TODO: move '-S djw' somewhere else
484 self.extra + 473 encode_args = self.extra + \
485 [self.encode_args, 474 [ '-S', 'djw' ] + \
486 self.presrc, 475 [self.encode_args,
487 self.old, 476 self.presrc,
488 self.new, 477 self.old,
489 DFILE]) 478 self.new,
490 if trial > 0: 479 DFILE]
491 return None 480
492 self.dinfo = Xdelta3Info(self.new,DFILE) 481 decode_args = [self.decode_args,
493 if self.dinfo.extcomp: 482 self.presrc,
494 raise SkipRcsException('ext comp') 483 self.old,
495 RunXdelta3([self.decode_args, 484 DFILE,
496 self.presrc, 485 RFILE]
497 self.old, 486 try:
498 DFILE, 487 RunXdelta3(encode_args)
499 RFILE]) 488 if trial > 0:
500 RunCommand(('cmp', 489 return None
501 self.new, 490 self.dinfo = Xdelta3Info(self.new,DFILE)
502 RFILE)) 491 if self.dinfo.extcomp:
503 return self.dinfo 492 raise SkipRcsException('ext comp')
493 RunXdelta3(decode_args)
494 RunCommand(('cmp',
495 self.new,
496 RFILE))
497 return self.dinfo
498 except CommandError:
499 print 'encode args: %s' % ' '.join(encode_args)
500 print 'decode args: %s' % ' '.join(decode_args)
504 501
505def Test(): 502def Test():
506 rcsf = RcsFinder() 503 rcsf = RcsFinder()
@@ -529,15 +526,10 @@ def Decimals(max):
529 return l 526 return l
530 527
531class Xdelta3Run1: 528class Xdelta3Run1:
532 def __init__(self,file,reps=0): 529 def __init__(self,file):
533 self.file = file 530 self.file = file
534 self.reps = reps 531 def Run(self,trial):
535 self.canrep = 1 532 RunXdelta3(['-efq', self.file, DFILE])
536 def Run(self,trial,reps):
537 if self.reps:
538 assert(reps == 1)
539 reps = self.reps
540 RunXdelta3(['-P', '%d' % reps, '-efq', self.file, DFILE])
541 if trial > 0: 533 if trial > 0:
542 return None 534 return None
543 return Xdelta3Info(self.file,DFILE) 535 return Xdelta3Info(self.file,DFILE)
@@ -546,8 +538,7 @@ class GzipRun1:
546 def __init__(self,file): 538 def __init__(self,file):
547 self.file = file 539 self.file = file
548 self.canrep = 0 540 self.canrep = 0
549 def Run(self,trial,reps): 541 def Run(self,trial):
550 assert(reps == 1)
551 RunCommandIO(['gzip', '-cf'], self.file, DFILE) 542 RunCommandIO(['gzip', '-cf'], self.file, DFILE)
552 if trial > 0: 543 if trial > 0:
553 return None 544 return None
@@ -560,8 +551,8 @@ def SetFileSize(F,L):
560 os.close(fd) 551 os.close(fd)
561 552
562def ReportSpeed(L,tr,desc): 553def ReportSpeed(L,tr,desc):
563 print '%s 0-run length %u: dsize %u: time %.3f ms: encode %.0f B/sec: in %ux%u trials' % \ 554 print '%s 0-run length %u: dsize %u: time %.3f ms: encode %.0f B/sec: in %u trials' % \
564 (desc, L, tr.r1.dsize, tr.time.mean * 1000.0, ((L+tr.r1.dsize) / tr.time.mean), tr.trials, tr.reps) 555 (desc, L, tr.r1.dsize, tr.time.mean * 1000.0, ((L+tr.r1.dsize) / tr.time.mean), tr.trials)
565 556
566def MakeBigFiles(rcsf): 557def MakeBigFiles(rcsf):
567 rand = random.Random() 558 rand = random.Random()
@@ -586,39 +577,6 @@ def MakeBigFiles(rcsf):
586 return (TMPDIR + "/big.1", 577 return (TMPDIR + "/big.1",
587 TMPDIR + "/big.2") 578 TMPDIR + "/big.2")
588 579
589def BigFileRun(f1, f2):
590
591 testcases = [
592 # large_look large_step small_look small_chain small_lchain
593 # ssmatch try_lazy max_lazy long_enough promote
594# ['-DC', '10,1,4,36,13,0,1,512,256,0'],
595# ['-DC', '10,1,4,36,13,0,1,256,128,0'],
596# ['-DC', '10,1,4,36,13,0,1,128,64,0'],
597# ['-DC', '10,1,4,36,13,0,1,64,32,0'],
598
599 ['-DC', '11,7,4,2,1,0,0,110,178,1'],
600 ['-DC', '11,7,4,3,1,0,0,110,178,1'],
601 ['-DC', '11,7,4,4,1,0,0,110,178,1'],
602 ['-DC', '11,7,4,5,1,0,0,110,178,1'],
603 ['-DC', '11,7,4,2,1,0,0,110,100,1'],
604 ['-DC', '11,7,4,2,1,0,0,110,50,1'],
605 ['-DC', '11,7,4,2,1,0,0,110,25,1'],
606 ]
607
608 for test in testcases:
609 runner = Xdelta3Pair()
610 runner.extra = test
611 result = TimeRun(runner.Runner(f1, 1, f2, 2))
612
613 print 'test %s dsize %d: time %.7f: in %u/%u trials' % \
614 (test,
615 result.r1.dsize,
616 result.time.mean,
617 result.trials,
618 result.reps)
619 #end
620 return 1
621
622class RandomTestResult: 580class RandomTestResult:
623 def __init__(self, round, config, runtime, compsize): 581 def __init__(self, round, config, runtime, compsize):
624 self.round = round 582 self.round = round
@@ -672,15 +630,15 @@ class RandomTester:
672 def RandomConfig(self): 630 def RandomConfig(self):
673 631
674 input_ranges = [ 632 input_ranges = [
675 (7, 9, 12, 'large_look'), 633 (9, 9, 9, 'large_look'),
676 (1, 9, 17, 'large_step'), 634 (1, 4.5, 8, 'large_step'),
677 (4, 4, 4, 'small_look'), # Note: disabled 635 (4, 4, 4, 'small_look'), # Note: disabled
678 (1, 10, 100, 'small_chain'), 636 (1, 10, 30, 'small_chain'),
679 (1, 5, 50, 'small_lchain'), 637 (1, 3.5, 6, 'small_lchain'),
680 (0, 0, 0, 'ssmatch'), # Note: disabled 638 (0, 0, 0, 'ssmatch'), # Note: disabled
681 (1, 1, 1, 'trylazy'), # Note: enabled 639 (1, 1, 1, 'trylazy'), # Note: enabled
682 (1, 128, 1024, 'max_lazy'), 640 (1, 128, 256, 'max_lazy'),
683 (1, 256, 2048, 'long_enough'), 641 (1, 256, 512, 'long_enough'),
684 (0, 0, 0, 'promote'), # Note: disabled 642 (0, 0, 0, 'promote'), # Note: disabled
685 ] 643 ]
686 644
@@ -697,7 +655,7 @@ class RandomTester:
697 else: 655 else:
698 val = -1 656 val = -1
699 while val < minv or val > maxv: 657 while val < minv or val > maxv:
700 val = int(self.random.expovariate(1.0 / mean)) 658 val = int(self.random.expovariate(1.0 / mean) + 0.5)
701 #end 659 #end
702 #end 660 #end
703 661
@@ -758,10 +716,14 @@ class RandomTester:
758 sized = [] 716 sized = []
759 717
760 for test in self.results: 718 for test in self.results:
719
720 # This scores ellipse has x-major (time) and y-minor (size)
761 ntime = (test.time()) / float(maxt) 721 ntime = (test.time()) / float(maxt)
762 nsize = (test.size()) / float(maxs) 722 nsize = (test.size()) / float(maxs)
763 score = math.sqrt((maxs / mins) * ntime * ntime + 723
764 (maxt / mint) * nsize * nsize) 724 wntime = ntime * (maxs / mins)
725 wnsize = nsize * (maxt / mint)
726 score = math.sqrt(wntime * wntime + wnsize * wnsize)
765 scored.append((score, test)) 727 scored.append((score, test))
766 timed.append((test.time(), test, score)) 728 timed.append((test.time(), test, score))
767 sized.append((test.size(), test, score)) 729 sized.append((test.size(), test, score))