<commit_before>/*
 * EventProcessingPerformanceMeter.java
 *
 * Created on August 20, 2006, 10:14 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 *
 *
 *Copyright August 20, 2006 <NAME>, Inst. of Neuroinformatics, UNI-ETH Zurich
 */

package net.sf.jaer.eventprocessing;

import net.sf.jaer.event.EventPacket;

/**
 * Measures cost of event processing.
 
 * @author tobi
 */
public class EventProcessingPerformanceMeter {
    private static final float SPNS = 1e-9f;
    public static final float NSPS = 1e9f;
    
    EventPacket packet;
    long startTimeNs, endTimeNs;
    int size=1;
    long durationSum, sumSquared;
    long durationNs=1;
    int nSamples=0;
    float thisNspe=0, nspeSum=0,nspeSq=0; // summary stats for ns per event
    EventFilter filter;
    String filterClassName;
    
    /** Creates a new instance of EventProcessingPerformanceMeter */
    public EventProcessingPerformanceMeter(EventFilter f) {
        this.filter=f;
        filterClassName=f.getClass().getSimpleName();
    }
    
    public void start(EventPacket packet){
        this.packet=packet;
        size=packet.getSize();
        startTimeNs=System.nanoTime();
    }
    
    public void start(int nEvents){
        size=nEvents;
        startTimeNs=System.nanoTime();
    }
    
    public void stop(){
        endTimeNs=System.nanoTime();
        durationNs=endTimeNs-startTimeNs;
        thisNspe=size==0? 0: durationNs/size;
        nspeSum+=thisNspe;
        nspeSq+=thisNspe*thisNspe;
        nSamples++;
    }
    
    public void stop(int nEvents){
        this.size=nEvents;
        stop();
    }
    
    public float eps(){
        return size/(SPNS*durationNs);
    }
    
    public float sPerEvent(){
        float eps=eps();
        if(eps==0) return 0; else return 1/eps;
    }
    
    public float avgSPerEvent(){
        return (float)nspeSum*SPNS/nSamples;
    }
    
    public float stdErrSecPerEvent(){
        if(nSamples<2) return 0;
        float avg=avgSPerEvent();
//        float avg=(float)durationSum/nSamples;
        float std=(float)Math.sqrt( ((float)nspeSq-((float)nspeSum*nspeSum)/nSamples)/(nSamples-1));
//        float std=(float)Math.sqrt( ((float)sumSquared-nSamples*avg*avg)/nSamples);
        return std*SPNS;
    }
    
    public void resetStatistics(){
        nSamples = 0;
        thisNspe = 0;
        nspeSum = 0;
        nspeSq = 0; // summary stats for ns per event
    }
    
//    public float meanEps(){
//        float m=durationSum/n
//    }
    
    public String toString(){
        String s=String.format("%s: %9d events, %8.3f ms, %8.2g eps, %8.1f ns/event (Average %8.1f +/- %-6.1f ns/event, N=%d samples), ", 
                filterClassName,
                size, 
                durationNs*1e-6f,
                eps(),
                NSPS*sPerEvent(),
                NSPS*avgSPerEvent(),
                NSPS*stdErrSecPerEvent(),
                nSamples
                );
        return s;
    }
    
}<commit_msg>added more detailed logging in RectangularClusterTracker<commit_after>/*
 * EventProcessingPerformanceMeter.java
 *
 * Created on August 20, 2006, 10:14 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 *
 *
 *Copyright August 20, 2006 <NAME>, Inst. of Neuroinformatics, UNI-ETH Zurich
 */

package net.sf.jaer.eventprocessing;

import net.sf.jaer.event.EventPacket;

/**
 * Measures cost of event processing.
 
 * @author tobi
 */
public class EventProcessingPerformanceMeter {
    private static final float SPNS = 1e-9f;
    public static final float NSPS = 1e9f;
    
    EventPacket packet;
    long startTimeNs, endTimeNs;
    int size=1;
    long durationSum, sumSquared;
    long durationNs=1;
    int nSamples=0;
    float thisNspe=0, nspeSum=0,nspeSq=0; // summary stats for ns per event
    EventFilter filter;
    String filterClassName;
    
    /** Creates a new instance of EventProcessingPerformanceMeter */
    public EventProcessingPerformanceMeter(EventFilter f) {
        this.filter=f;
        filterClassName=f.getClass().getSimpleName();
    }
    
    public void start(EventPacket packet){
        this.packet=packet;
        size=packet.getSize();
        startTimeNs=System.nanoTime();
    }
    
    public void start(int nEvents){
        size=nEvents;
        startTimeNs=System.nanoTime();
    }
    
    public void stop(){
        endTimeNs=System.nanoTime();
        durationNs=endTimeNs-startTimeNs;
        thisNspe=size==0? 0: durationNs/size;
        nspeSum+=thisNspe;
        nspeSq+=thisNspe*thisNspe;
        nSamples++;
    }
    
    public void stop(int nEvents){
        this.size=nEvents;
        stop();
    }
    
    public float eps(){
        return size/(SPNS*durationNs);
    }
    
    public float sPerEvent(){
        float eps=eps();
        if(eps==0) return 0; else return 1/eps;
    }
    
    public float avgSPerEvent(){
        return (float)nspeSum*SPNS/nSamples;
    }
    
    public float stdErrSecPerEvent(){
        if(nSamples<2) return 0;
        float avg=avgSPerEvent();
//        float avg=(float)durationSum/nSamples;
        float std=(float)Math.sqrt( ((float)nspeSq-((float)nspeSum*nspeSum)/nSamples)/(nSamples-1));
//        float std=(float)Math.sqrt( ((float)sumSquared-nSamples*avg*avg)/nSamples);
        return std*SPNS;
    }
    
    public void resetStatistics(){
        nSamples = 0;
        thisNspe = 0;
        nspeSum = 0;
        nspeSq = 0; // summary stats for ns per event
    }
    
//    public float meanEps(){
//        float m=durationSum/n
//    }
    
    public String toString(){
        String s=String.format("%s: %9d events, start %16d ns, duration %8.3f ms, %8.2g eps, %8.1f ns/event (Average %8.1f +/- %-6.1f ns/event, N=%d samples), ", 
                filterClassName,
                size,
                startTimeNs,
                durationNs*1e-6f,
                eps(),
                NSPS*sPerEvent(),
                NSPS*avgSPerEvent(),
                NSPS*stdErrSecPerEvent(),
                nSamples
                );
        return s;
    }
    
}
{'fraction_non_alphanumeric': 0.11157894736842106, 'fraction_numerical': 0.016842105263157894, 'mean_word_length': 2.1671794871794874, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '6817062', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1918, 'n_words': 446}