Пример #1
0
 def test(sorter, n, seed, *args):
     if len(args) == 0:
         m = 0
     elif len(args) == 1:
         m = args[0]
     else:
         raise ValueError
     RandomNumberGenerator.seed = seed
     data = Array(n)
     for i in xrange(n):
         datum = int(sys.maxint * RandomNumberGenerator.next)
         if m != 0:
             datum %= m
         data[i] = datum
     timer = Timer()
     timer.start()
     sorter.sort(data)
     timer.stop()
     datum = "%s %s %s %g" % (sorter.__class__.__name__, n, seed,
                              timer.getElapsedTime())
     print datum
     sys.stderr.write(datum + "\n")
     for i in xrange(1, n):
         if data[i] < data[i - 1]:
             print "FAILED"
             break
Пример #2
0
 def test(sorter, n, seed, *args):
     if len(args) == 0:
         m = 0
     elif len(args) == 1:
         m = args[0]
     else:
         raise ValueError
     RandomNumberGenerator.seed = seed
     data = Array(n)
     for i in xrange(n):
         datum = int(sys.maxint * RandomNumberGenerator.next)
         if m != 0:
             datum %= m
         data[i] = datum
     timer = Timer()
     timer.start()
     sorter.sort(data)
     timer.stop()
     datum = "%s %s %s %g" % (
         sorter.__class__.__name__, n, seed, timer.getElapsedTime())
     print datum
     sys.stderr.write(datum + "\n")
     for i in xrange(1, n):
         if data[i] < data[i - 1]:
             print "FAILED"
             break
Пример #3
0
    def main(*argv):
        "Experiment1 test program."
        print "3"
        print "n"
        print "fib1 s"
        print "fib2 s"
        timer1 = Timer()
        timer2 = Timer()
        for i in xrange(49):
            timer1.start()
            result = example.Fibonacci1(i)
            timer1.stop()

            timer2.start()
            result = example.Fibonacci2(i)
            timer2.stop()

            datum = "%d\t%g\t%g" % (
                i, timer1.getElapsedTime(), timer2.getElapsedTime())
            print datum
            sys.stderr.write(datum + "\n")
        return 0
Пример #4
0
    def main(*argv):
        "Experiment1 test program."
        print "3"
        print "n"
        print "fib1 s"
        print "fib2 s"
        timer1 = Timer()
        timer2 = Timer()
        for i in xrange(49):
            timer1.start()
            result = example.Fibonacci1(i)
            timer1.stop()

            timer2.start()
            result = example.Fibonacci2(i)
            timer2.stop()

            datum = "%d\t%g\t%g" % (i, timer1.getElapsedTime(),
                                    timer2.getElapsedTime())
            print datum
            sys.stderr.write(datum + "\n")
        return 0