<commit_before>import timeit
from arangodb.api import Client, Database, Collection


##################################
# These tests
##################################

# Init client
client = Client('localhost')

# Create database in which all collections are created
database_name = 'arangopy_speed_test_database'
try:
    Database.create(database_name)
except:
    client.set_database(database_name)


timer = timeit.default_timer

# Everything needs to be in one try-catch so we can clean up afterwards
try:

    document_number = 10**6 # 1 million
    big_collection_name = 'big_collection'
    big_collection = Collection.create(big_collection_name)

    start = timer()

    for i in range(1, document_number):
        doc = big_collection.create_document()
        doc.index = i
        doc.save()

    elapsed = timer() - start

    print('Adding %s documents to the collection took %s milliseconds' % ( document_number, elapsed) )

    Collection.remove(big_collection_name)

except Exception as err:
    print(err)
<commit_msg>Put all the timing into functions<commit_after>import timeit
from arangodb.api import Client, Database, Collection


##################################
# These tests
##################################

# Init client
from arangodb.query.advanced import Query
from arangodb.query.simple import SimpleQuery

client = Client('localhost')

# Create database in which all collections are created
database_name = 'arangopy_speed_test_database'
try:
    Database.create(database_name)
except:
    client.set_database(database_name)


timer = timeit.default_timer

def timer_decorator(message):
    def outer_wrapper(func):
        def wrapper(*args, **kwargs):
            start = timer()
            func(*args, **kwargs)
            elapsed = timer() - start
            print(message % elapsed)

        return wrapper

    return outer_wrapper


document_number = 10**6 # 10 thousand

@timer_decorator('Adding documents to the collection took %s seconds')
def create_big_number_of_documents(big_collection):
    """
    """

    for i in range(1, document_number):
        doc = big_collection.create_document()
        doc.index = i
        doc.save()

@timer_decorator('Retrieving %s documents normally from the collection took %s seconds')
def retrieve_normally_documents(big_collection):
    """
    """

    big_collection.documents()

@timer_decorator('Retrieving %s documents via simple query from the collection took %s seconds')
def retrieve_simply_documents(big_collection):
    """
    """

    SimpleQuery.all(collection=big_collection)

@timer_decorator('Retrieving %s documents via aql from the collection took %s seconds')
def retrieve_aql_documents(big_collection):
    """
    """

    all_aql_query = Query()
    all_aql_query.append_collection(collection_name=big_collection.name)
    all_aql_query.execute()

# Everything needs to be in one try-catch so we can clean up afterwards
try:

    big_collection_name = 'big_collection'
    big_collection = Collection.create(big_collection_name)

    print('All tests are using either %s documents, edges or models' % document_number)

    # Create first all documents
    create_big_number_of_documents(big_collection)

    # Get all documents normally
    retrieve_normally_documents(big_collection)

    # Get documents with simple query
    retrieve_simply_documents(big_collection)

    # Get documents with aql
    retrieve_aql_documents(big_collection)

    # Delete all documents
    Collection.remove(big_collection_name)

except Exception as err:
    print(err)

{'fraction_non_alphanumeric': 0.11400560224089636, 'fraction_numerical': 0.0030812324929971988, 'mean_word_length': 4.182873730043541, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2062861', 'n_tokens_mistral': 1020, 'n_tokens_neox': 976, 'n_words': 275}