Skip to content

Instantly share code, notes, and snippets.

@Girgitt
Girgitt / ProfilerLog.py
Last active February 28, 2024 09:06
small class to quickly profile execution in python without decomposing your code into functions to use "timeit" decorators etc.
class ProfilerLog(object):
def __init__(self, profiler_name="", start_ts=None):
self._profiler_name = profiler_name
self._start_ts = start_ts if start_ts else time.time()
self._steps_data = OrderedDict()
self._aux_data = {}
def step(self, step_name, begin_ts=None, end_ts=None):
if step_name not in self._steps_data:
begin_ts = begin_ts if begin_ts else time.time()
@Girgitt
Girgitt / gist:c69b461c5bf4dad42cee3421b0ac0e2f
Last active January 4, 2024 09:08
disk cleaner - code to keep system running in case of disk space exhaustion e.g. by excessive logging or other unexpected condition
#!/usr/bin/env python3
import os
import time
import datetime
import argparse
from sys import exit
from pathlib import Path
from typing import Iterator, Tuple
from shutil import disk_usage, rmtree
@Girgitt
Girgitt / text_search_profiling.py
Created January 16, 2024 11:31
text element search time in python: list vs. set
import timeit
import random
import string
# Function to generate random text of length 32
def generate_random_text():
return ''.join(random.choices(string.ascii_letters + string.digits, k=32))
# Generate a list of a couple of hundred random text values
random_text_list = [generate_random_text() for _ in range(400000)]