<commit_before>from logging import getLogger
import time

from streamkinect2.mock import MockKinect
from streamkinect2.compress import DepthFrameCompressor

def main():
    wait_time = 5

    print('Running compressed pipeline for {0} seconds...'.format(wait_time))
    packets = []
    with MockKinect() as kinect:
        fc = DepthFrameCompressor(kinect)
        @fc.on_compressed_frame.connect_via(fc)
        def new_compressed_frame(_, compressed_frame):
            packets.append(compressed_frame)
        then = time.time()
        time.sleep(5)
        now = time.time()
    delta = now - then
    data_size = sum(len(p) for p in packets)
    data_rate = float(data_size) / delta # bytes/sec
    pps = len(packets) / delta
    print('Mock kinect runs at {0:.2f} packets/second w/ compression'.format(pps))
    print('Data rate is {0:2f} Mbytes/second'.format(data_rate / (1024*1024)))

    print('Running mock kinect for {0} seconds...'.format(wait_time))
    state = { 'n_frames': 0 }
    with MockKinect() as kinect:
        then = time.time()
        @kinect.on_depth_frame.connect_via(kinect)
        def f(kinect, depth_frame):
            state['n_frames'] += 1
        time.sleep(wait_time)
        now = time.time()
    delta = now - then
    fps = state['n_frames'] / delta
    print('Mock kinect runs at {0:.2f} frames/second'.format(fps))

if __name__ == '__main__':
    main()<commit_msg>benchmark_mock_kinect: refactor to be a little cleaner<commit_after>from logging import getLogger
import time

from streamkinect2.mock import MockKinect
from streamkinect2.compress import DepthFrameCompressor

def benchmark_compressed(wait_time):
    print('Running compressed pipeline for {0} seconds...'.format(wait_time))
    packets = []
    with MockKinect() as kinect:
        fc = DepthFrameCompressor(kinect)
        @fc.on_compressed_frame.connect_via(fc)
        def new_compressed_frame(_, compressed_frame):
            packets.append(compressed_frame)
        then = time.time()
        time.sleep(5)
        now = time.time()
    delta = now - then
    data_size = sum(len(p) for p in packets)
    data_rate = float(data_size) / delta # bytes/sec
    pps = len(packets) / delta
    print('Mock kinect runs at {0:.2f} packets/second w/ compression'.format(pps))
    print('Data rate is {0:2f} Mbytes/second'.format(data_rate / (1024*1024)))

def benchmark_mock(wait_time):
    print('Running mock kinect for {0} seconds...'.format(wait_time))
    state = { 'n_frames': 0 }
    with MockKinect() as kinect:
        then = time.time()
        @kinect.on_depth_frame.connect_via(kinect)
        def f(kinect, depth_frame):
            state['n_frames'] += 1
        time.sleep(wait_time)
        now = time.time()
    delta = now - then
    fps = state['n_frames'] / delta
    print('Mock kinect runs at {0:.2f} frames/second'.format(fps))

def main():
    wait_time = 5
    benchmark_compressed(wait_time)
    benchmark_mock(wait_time)

if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.11853088480801335, 'fraction_numerical': 0.014691151919866445, 'mean_word_length': 3.0651289009497966, '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': '2247966', 'n_tokens_mistral': 1033, 'n_tokens_neox': 995, 'n_words': 233}