<commit_before>from __future__ import print_function, division, absolute_import

import collections
import inspect
import time
from utility.tools import LOG_BENCH


class Bench(object):
    entries = collections.OrderedDict()

    def __init__(self, name=None, write_output=True):
        self.name = name
        self.write_output = write_output

    def __enter__(self):
        if self.write_output:
            if self.name:
                print("Starting benchmark: %s" % (self.name))
            else:
                print("Starting benchmark at: %s [%i]" % (inspect.stack()[1][3], inspect.stack()[1][2]))
        self.start_time = time.time()

    def __exit__(self, type, value, traceback):
        time_taken = time.time() - self.start_time
        if self.write_output:
            if self.name:
                name = self.name
            else:
                name = "That"

            print("  %s took: %f seconds" % (name, (time_taken)))<commit_msg>Use logger also for benchmarking<commit_after>from __future__ import print_function, division, absolute_import

import collections
import inspect
import time
from utility.tools import LOG_BENCH

from utility.logger import getLogger
logger = getLogger(__name__ )

class Bench(object):
    entries = collections.OrderedDict()

    def __init__(self, name=None, write_output=True):
        self.name = name
        self.write_output = write_output

    def __enter__(self):
        if self.write_output:
            if self.name:
                logger.debug("Starting benchmark: %s" % (self.name))
            else:
                logger.debug("Starting benchmark at: %s [%i]" % (inspect.stack()[1][3], inspect.stack()[1][2]))
        self.start_time = time.time()

    def __exit__(self, type, value, traceback):
        time_taken = time.time() - self.start_time
        if self.write_output:
            if self.name:
                name = self.name
            else:
                name = "That"

            logger.info("  %s took: %f seconds" % (name, (time_taken)))
{'fraction_non_alphanumeric': 0.11029411764705882, 'fraction_numerical': 0.00392156862745098, 'mean_word_length': 2.3624382207578254, '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': '1335553', 'n_tokens_mistral': 608, 'n_tokens_neox': 573, 'n_words': 153}