Example #1
0
def run(lcsMethod, verbose=False):
    done = False
    n = 1

    grow_fast = lcsMethod is not lcs.naiveGetLCS
    while not done:
        # generate a random sequence of 0 and 1 characters
        # first = ''.join(random.choice(['0', '1']) for x in range(n))
        # second = ''.join(random.choice(['0', '1']) for x in range(n))

        # use this for benchmarking "fixed" strings
        # this forces the worst case for naive
        first = '0' * n
        second = '1' * n
        seconds, output = profiler.run(lcsMethod, first, second)
        if seconds > 10:
            print output
            done = True
        else:
            if verbose:
                print 'N(' + str(n) + ')  => ' + str(seconds) + ' CPU seconds'
            if grow_fast:
                if n == 1:
                    n = 2
                elif seconds > 2:
                    n = int((n * max((1 - seconds / 10), 0.1)) + n)
                else:
                    n = n * 2
            else:
                n += 1
Example #2
0
def run(lcsMethod, verbose=False):
    done = False
    n = 1

    grow_fast = lcsMethod is not lcs.naiveGetLCS
    while not done:
        # generate a random sequence of 0 and 1 characters
        # first = ''.join(random.choice(['0', '1']) for x in range(n))
        # second = ''.join(random.choice(['0', '1']) for x in range(n))

        # use this for benchmarking "fixed" strings
        # this forces the worst case for naive
        first = "0" * n
        second = "1" * n
        seconds, output = profiler.run(lcsMethod, first, second)
        if seconds > 10:
            print output
            done = True
        else:
            if verbose:
                print "N(" + str(n) + ")  => " + str(seconds) + " CPU seconds"
            if grow_fast:
                if n == 1:
                    n = 2
                elif seconds > 2:
                    n = int((n * max((1 - seconds / 10), 0.1)) + n)
                else:
                    n = n * 2
            else:
                n += 1
Example #3
0
    if sys.argv[2] == 's':
	verbose = False
	fixedLength = -1
	if len(sys.argv) >= 4 and sys.argv[3] != 'v':
		fixedLength =int(sys.argv[3])
        if sys.argv[-1]=='v':
		verbose =True
        for lcsMethod in algList:
            if fixedLength <= -1:
                print 'Finding length n strings to get close to ~10 seconds computation for algorithm ', lcsMethods[lcsMethod][1]
                stress.run(lcsMethods[lcsMethod][0],verbose)
            else:
                first = '0' * fixedLength
                second = '1' * fixedLength
                print 'Using length',fixedLength,'strings to stress test for algorithm ', lcsMethods[lcsMethod][1]
                print profiler.run(lcsMethods[lcsMethod][0], first, second)[1]

    elif sys.argv[2] == 'r':
	maxLengthFirst = 20
	minLengthFirst = 1
	maxLengthSecond = 20
	minLengthSecond = 1
	if len(sys.argv) >= 4:
		maxLengthFirst = int(sys.argv[3])
	if len(sys.argv) >= 5:
		maxLengthSecond = int(sys.argv[4])
	if len(sys.argv) >= 6:
		minLengthFirst = int(sys.argv[5])
	if len(sys.argv) >= 7:
		minLengthSecond = int(sys.argv[6])
        #generate a random sequence of 0 and 1 characters
Example #4
0
        fixedLength = -1
        if len(sys.argv) >= 4 and sys.argv[3] != 'v':
            fixedLength = int(sys.argv[3])
        if sys.argv[-1] == 'v':
            verbose = True
        for lcsMethod in algList:
            if fixedLength <= -1:
                print 'Finding length n strings to get close to ~10 seconds computation for algorithm ', lcsMethods[
                    lcsMethod][1]
                stress.run(lcsMethods[lcsMethod][0], verbose)
            else:
                first = '0' * fixedLength
                second = '1' * fixedLength
                print 'Using length', fixedLength, 'strings to stress test for algorithm ', lcsMethods[
                    lcsMethod][1]
                print profiler.run(lcsMethods[lcsMethod][0], first, second)[1]

    elif sys.argv[2] == 'r':
        maxLengthFirst = 20
        minLengthFirst = 1
        maxLengthSecond = 20
        minLengthSecond = 1
        if len(sys.argv) >= 4:
            maxLengthFirst = int(sys.argv[3])
        if len(sys.argv) >= 5:
            maxLengthSecond = int(sys.argv[4])
        if len(sys.argv) >= 6:
            minLengthFirst = int(sys.argv[5])
        if len(sys.argv) >= 7:
            minLengthSecond = int(sys.argv[6])
    #generate a random sequence of 0 and 1 characters