def showDiagram():
    profile.fire()
    xml = """<?xml version="1.0" encoding="utf-8" ?>
<table>
    <row>
        <table>
            <row>
                <cell>First</cell>
                <cell>Second</cell>
            </row>
        </table>
        <cell>Python</cell>
    </row>
    <row>
        <cell>Speed</cell>
        <cell>Slow</cell>
    </row>
</table>
    """
    arr = reader.newBytes(len(xml))
    for i in range(0, len(xml)):
        arr[i] = JByte(ord(xml[i]))
        print arr[i]
    print "OK"
    rgba = reader.toDiagram(arr)
    profile.check()
    length = len(rgba)
    b = bytearray(length)
    for i in range(0, length):
        b[i] = (rgba[i] & 0xff)
    image = Image.open(io.BytesIO(b))
    image.show()
示例#2
0
def test():
    for i in range(12, 25):
        length = 2 << i
        arr = [complex(random.random(), 0) for __i__ in range(0, length)]
        profile.fire()
        iter_fft(arr)
        time = profile.check()
示例#3
0
def test(n):
    bt = BTree()
    a = [__i__ for __i__ in range(0, n)]
    random.shuffle(a)
    c = 0

    profile.fire()
    for __i__ in a:
        bt.insert(__i__)
        #print '------------------------------------------------------------------------------------------'
        #print '%d: inserted %d' % (c, __i__)
        #bt.print_self()
        c += 1
    # bt.print_self()
    profile.check()
    return bt
示例#4
0
def max_sub(array):
    max_sum = 0
    for i in range(0, len(array)):
        for j in range(i, len(array)):
            max_sum = max(max_sum, sum(array[i: j]))
    return max_sum


def max_sub_opt(array):
    max_sum = 0
    max_current = 0
    for i in array:
        max_current += i
        if max_current < 0:
            max_current = 0
        elif i > 0:
            max_sum = max(max_sum, max_current)
    return max_sum


if __name__ == '__main__':
    while True:
        length = raw_input('>>> ')
        arr = [random.randint(-1000, 1000) for i in range(0, int(length))]
        profile.fire()
        print max_sub_opt(arr)
        profile.check()
        profile.fire()
        print max_sub(arr)
        profile.check()