<commit_before>package de.omnikryptec.util;

import java.util.HashMap;
import java.util.Map;

import de.omnikryptec.util.data.FixedStack;
import de.omnikryptec.util.math.Mathd;

public class Profiler {
    
    private static class Struct {
        long sum;
        long count;
        boolean open;
    }
    
    private static final Map<String, Struct> map = new HashMap<>();
    private static final FixedStack<String> h = new FixedStack<>(20);
    
    public static void clear() {
        map.clear();
        h.clear();
    }
    
    private static Struct get(String id) {
        Struct s = map.get(id);
        if (s == null) {
            s = new Struct();
            map.put(id, s);
        }
        return s;
    }
    
    public static void begin(String id) {
        Struct s = get(id);
        if (s.open) {
            throw new IllegalStateException("never ended profiling with ID " + id);
        }
        s.count++;
        s.open = true;
        h.push(id);
        long time = System.nanoTime();
        s.sum += -time;
    }
    
    //TODO insert specific data (vertex count, flush count, etc)
    public static void end() {
        long time = System.nanoTime();
        String id = h.pop();
        Struct s = get(id);
        if (!s.open) {
            throw new IllegalStateException("never started profiling with ID " + id);
        }
        s.sum += time;
        s.open = false;
    }
    
    public static String currentInfo() {
        if (map.isEmpty()) {
            return "";
        }
        StringBuilder b = new StringBuilder();
        for (String id : map.keySet()) {
            Struct s = map.get(id);
            if (s.open) {
                throw new IllegalStateException("the profiling with ID " + id + " is still open");
            }
            b.append("-------------------\n");
            b.append("ID: " + id).append('\n');
            b.append("Count: " + s.count).append('\n');
            b.append("Average time: " + Mathd.round((s.sum / (double) s.count) * 1e-6, 3) + "ms").append('\n');
            b.append("Complete time spend: " + Mathd.round(s.sum * 1e-9, 5) + "s").append('\n');
        }
        b.append("-------------------");
        return b.toString();
    }
    
}<commit_msg>improved Profiler<commit_after>package de.omnikryptec.util;

import java.util.HashMap;
import java.util.Map;

import de.omnikryptec.util.data.FixedStack;
import de.omnikryptec.util.math.Mathd;

public class Profiler {
    //TODO improve min and max stuff
    
    private static class Struct {
        long sum;
        long count;
        long max = Long.MIN_VALUE;
        long min = Long.MAX_VALUE;
        boolean open;
        
        long beginTimeTmp;
    }
    
    private static final Map<String, Struct> map = new HashMap<>();
    private static final FixedStack<String> h = new FixedStack<>(20);
    
    public static void clear() {
        map.clear();
        h.clear();
    }
    
    private static Struct get(String id) {
        Struct s = map.get(id);
        if (s == null) {
            s = new Struct();
            map.put(id, s);
        }
        return s;
    }
    
    public static void begin(String id) {
        Struct s = get(id);
        if (s.open) {
            throw new IllegalStateException("never ended profiling with ID " + id);
        }
        s.count++;
        s.open = true;
        h.push(id);
        long time = System.nanoTime();
        s.sum += -time;
        s.beginTimeTmp = time;
    }
    
    //TODO insert specific data (vertex count, flush count, etc)
    public static void end() {
        long time = System.nanoTime();
        String id = h.pop();
        Struct s = get(id);
        if (!s.open) {
            throw new IllegalStateException("never started profiling with ID " + id);
        }
        long dif = time - s.beginTimeTmp;
        s.sum += time;
        s.max = Math.max(dif, s.max);
        s.min = Math.min(dif, s.min);
        s.open = false;
    }
    
    public static String currentInfo() {
        if (map.isEmpty()) {
            return "";
        }
        StringBuilder b = new StringBuilder();
        for (String id : map.keySet()) {
            Struct s = map.get(id);
            if (s.open) {
                throw new IllegalStateException("the profiling with ID " + id + " is still open");
            }
            b.append("-------------------\n");
            b.append("ID: " + id).append('\n');
            b.append("Count: " + s.count).append('\n');
            b.append("Average time: " + Mathd.round((s.sum / (double) s.count) * 1e-6, 3) + "ms").append('\n');
            b.append("Complete time spend: " + Mathd.round(s.sum * 1e-9, 5) + "s").append('\n');
            b.append("Min time: " + Mathd.round((s.min) * 1e-6, 3) + "ms").append('\n');
            b.append("Max time: " + Mathd.round((s.max) * 1e-6, 3) + "ms").append('\n');
        }
        b.append("-------------------");
        return b.toString();
    }
    
}
{'fraction_non_alphanumeric': 0.15677626303127506, 'fraction_numerical': 0.004410585404971933, 'mean_word_length': 1.6244082062072593, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4222042', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1520, 'n_words': 395}