Exemplo n.º 1
0

if __name__ == "__main__":
    random.seed(None)

    # Build temporary files
    temp_files = []
    for charset_name, charset_generator in CHARSETS:
        for string_length in powerOf2Range(STRING_LENGTH_START,
                                           STRING_LENGTH_END):
            temp = tempfile.NamedTemporaryFile()
            for i in xrange(NUM_STRINGS):
                s = charset_generator(string_length)
                assert len(s) == string_length
                temp.write(s.encode("UTF-8"))
                temp.write("\n")
            temp.flush()
            temp_files.append((charset_name, string_length, temp))

    output = [("encoder", "charset", "string length", "chars per us")]
    for encoder_type in ("jdk", "generic", "bytebuffer", "reflect"):
        for charset_name, string_length, temp in temp_files:
            results = runTest(encoder_type, temp.name)
            print encoder_type, charset_name, string_length, bytebuffer.average(
                results)

            for value in results:
                output.append(
                    (encoder_type, charset_name, string_length, value))
    bytebuffer.saveCSVResults("stringbytebuffer.csv", output)
Exemplo n.º 2
0
    while start < max:
        yield start
        start *= 2


if __name__ == "__main__":
    random.seed(None)

    # Build temporary files
    temp_files = []
    for charset_name, charset_generator in CHARSETS:
        for string_length in powerOf2Range(STRING_LENGTH_START, STRING_LENGTH_END):
            temp = tempfile.NamedTemporaryFile()
            for i in xrange(NUM_STRINGS):
                s = charset_generator(string_length)
                assert len(s) == string_length
                temp.write(s.encode("UTF-8"))
                temp.write("\n")
            temp.flush()
            temp_files.append((charset_name, string_length, temp))

    output = [("encoder", "charset", "string length", "chars per us")]
    for encoder_type in ("jdk", "generic", "bytebuffer", "reflect"):
        for charset_name, string_length, temp in temp_files:
            results = runTest(encoder_type, temp.name)
            print encoder_type, charset_name, string_length, bytebuffer.average(results)

            for value in results:
                output.append((encoder_type, charset_name, string_length, value))
    bytebuffer.saveCSVResults("stringbytebuffer.csv", output)
Exemplo n.º 3
0
#!/usr/bin/python

import bytebuffer

TEST = "StringDecodingTest"
INPUT = "utf8.txt"

def runTest(conversion_type, reuse):
    process = bytebuffer.runJava(TEST, (conversion_type, reuse, INPUT))
    
    results = []
    for line in process.stdout:
        results.append(float(line.split()[0]))

    # Drop the first result due to optimization sucking at first
    return results[1:]


if __name__ == "__main__":
    output = []
    for conversion_type in ("chardecoder", "string", "custom"):
        for reuse in ("once", "reuse"):
            results = runTest(conversion_type, reuse)
            print conversion_type, reuse, bytebuffer.average(results)

            for value in results:
                output.append((conversion_type, reuse, value))

    bytebuffer.saveCSVResults("stringdecoding.csv", output)