def get_document_length(fileobject):
    """ Fast way to compute the length of a document;
     See: https://stackoverflow.com/questions/845058/how-to-get-line-count-cheaply-in-python """
    # Set up source file and buffer
    file = open(fileobject, 'rb')
    lines = 0
    buffer_size = 1024 * 1024
    read_file = file.raw.read

    # Count lines
    buffer = read_file(buffer_size)
    while buffer:
        lines += buffer.count(b'\n')
        buffer = read_file(buffer_size)
    file.close()

    return lines