# Path: pypet/tests/testutils/ioutils.py
# def make_temp_dir(filename, signal=False):
#     """Creates a temporary folder and returns the joined filename"""
#     try:
# 
#         if ((testParams['user_tempdir'] is not None and testParams['user_tempdir'] != '') and
#                         testParams['actual_tempdir'] == ''):
#             testParams['actual_tempdir'] = testParams['user_tempdir']
# 
#         if not os.path.isdir(testParams['actual_tempdir']):
#             os.makedirs(testParams['actual_tempdir'])
# 
#         return os.path.join(testParams['actual_tempdir'], filename)
#     except OSError as exc:
#         actual_tempdir = os.path.join(tempfile.gettempdir(), testParams['tempdir'])
# 
#         if signal:
#             errwrite('I used `tempfile.gettempdir()` to create the temporary folder '
#                              '`%s`.' % actual_tempdir)
#         testParams['actual_tempdir'] = actual_tempdir
#         if not os.path.isdir(testParams['actual_tempdir']):
#             try:
#                 os.makedirs(testParams['actual_tempdir'])
#             except Exception:
#                 pass # race condition
# 
#         return os.path.join(actual_tempdir, filename)
#     except:
#         get_root_logger().error('Could not create a directory.')
#         raise


from pypet.tests.testutils.ioutils import make_temp_dir
import tables as pt
import tables.parameters
import time
import os
import numpy as np
import matplotlib.pyplot as plt
def appendtime(table, length):

    runtimes = []
    for irun in range(length):
        start = time.time()

        row = table.row
        row['test'] = 'testing'
        row.append()
        table.flush()

        end = time.time()

        runtime = end-start
        runtimes.append(runtime)
    return np.mean(runtimes)

def make_table(hdf5_file, length):
    description = {'test' : pt.StringCol(42)}
    table = hdf5_file.create_table(where='/', name='t%d' % length, description=description)
    return table

def table_runtime(filename, length):
    hdf5_file = pt.open_file(filename, mode='w')
    table = make_table(hdf5_file, length)
    appendtimes = appendtime(table, length)
    hdf5_file.close()
    return appendtimes

def compute_runtime():

# Path: pypet/tests/testutils/ioutils.py
# def make_temp_dir(filename, signal=False):
#     """Creates a temporary folder and returns the joined filename"""
#     try:
# 
#         if ((testParams['user_tempdir'] is not None and testParams['user_tempdir'] != '') and
#                         testParams['actual_tempdir'] == ''):
#             testParams['actual_tempdir'] = testParams['user_tempdir']
# 
#         if not os.path.isdir(testParams['actual_tempdir']):
#             os.makedirs(testParams['actual_tempdir'])
# 
#         return os.path.join(testParams['actual_tempdir'], filename)
#     except OSError as exc:
#         actual_tempdir = os.path.join(tempfile.gettempdir(), testParams['tempdir'])
# 
#         if signal:
#             errwrite('I used `tempfile.gettempdir()` to create the temporary folder '
#                              '`%s`.' % actual_tempdir)
#         testParams['actual_tempdir'] = actual_tempdir
#         if not os.path.isdir(testParams['actual_tempdir']):
#             try:
#                 os.makedirs(testParams['actual_tempdir'])
#             except Exception:
#                 pass # race condition
# 
#         return os.path.join(actual_tempdir, filename)
#     except:
#         get_root_logger().error('Could not create a directory.')
#         raise


# Path: pypet/tests/profiling/speed_analysis/pytables_testing_append.py
from pypet.tests.testutils.ioutils import make_temp_dir
import tables as pt
import tables.parameters
import time
import os
import numpy as np
import matplotlib.pyplot as plt

def appendtime(table, length):

    runtimes = []
    for irun in range(length):
        start = time.time()

        row = table.row
        row['test'] = 'testing'
        row.append()
        table.flush()

        end = time.time()

        runtime = end-start
        runtimes.append(runtime)
    return np.mean(runtimes)

def make_table(hdf5_file, length):
    description = {'test' : pt.StringCol(42)}
    table = hdf5_file.create_table(where='/', name='t%d' % length, description=description)
    return table

def table_runtime(filename, length):
    hdf5_file = pt.open_file(filename, mode='w')
    table = make_table(hdf5_file, length)
    appendtimes = appendtime(table, length)
    hdf5_file.close()
    return appendtimes

def compute_runtime():

    filename = os.path.join(make_temp_dir('tests'), 'iterrow.hdf5')