<commit_before>/*
 * Copyright 2018, <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.fkeglevich.rawdumper.debug;

import android.util.Log;

import com.fkeglevich.rawdumper.BuildConfig;

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

/**
 * PerfInfo contains useful methods for measuring time cost of certain operations
 *
 * Created by <NAME> on 02/04/18.
 */

public class PerfInfo
{
    private static final String TAG = "PerfInfo";
    private static final boolean FORCE_PERFORMANCE_TRACKING = false;

    private static final Map<String, Long> tickingMap = new HashMap<>();
    private static final double NANO_TIME_TO_MILLISECONDS = 1000000.0;

    /**
     * Starts measuring performance
     * @param tag   A tag for storing/querying the result
     */
    public static void start(String tag)
    {
        if (BuildConfig.DEBUG || FORCE_PERFORMANCE_TRACKING)
            tickingMap.put(tag, System.nanoTime());
    }

    /**
     * Ends measuring performance and logs the result
     * @param tag   A tag for storing/querying the result
     */
    public static void end(String tag)
    {
        if (BuildConfig.DEBUG || FORCE_PERFORMANCE_TRACKING)
        {
            log(tag);
            tickingMap.remove(tag);
        }
    }

    /**
     * Logs the performance delta, measured in milliseconds
     * @param tag   A tag for storing/querying the result
     */
    public static void log(String tag)
    {
        if (BuildConfig.DEBUG || FORCE_PERFORMANCE_TRACKING)
        {
            double milliseconds = ((System.nanoTime() - tickingMap.get(tag)) / NANO_TIME_TO_MILLISECONDS);
            Log.i(TAG, tag + " needed " + milliseconds + " ms");
        }
    }
}
<commit_msg>Simple hack to log using System.out when testing<commit_after>/*
 * Copyright 2018, <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.fkeglevich.rawdumper.debug;

import android.util.Log;

import com.fkeglevich.rawdumper.BuildConfig;

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

/**
 * PerfInfo contains useful methods for measuring time cost of certain operations
 *
 * Created by <NAME> on 02/04/18.
 */

public class PerfInfo
{
    private static final String TAG = "PerfInfo";
    private static final boolean FORCE_PERFORMANCE_TRACKING = false;

    private static final Map<String, Long> tickingMap = new HashMap<>();
    private static final double NANO_TIME_TO_MILLISECONDS = 1000000.0;

    /**
     * Starts measuring performance
     * @param tag   A tag for storing/querying the result
     */
    public static void start(String tag)
    {
        if (BuildConfig.DEBUG || FORCE_PERFORMANCE_TRACKING)
            tickingMap.put(tag, System.nanoTime());
    }

    /**
     * Ends measuring performance and logs the result
     * @param tag   A tag for storing/querying the result
     */
    public static void end(String tag)
    {
        if (BuildConfig.DEBUG || FORCE_PERFORMANCE_TRACKING)
        {
            log(tag);
            tickingMap.remove(tag);
        }
    }

    /**
     * Logs the performance delta, measured in milliseconds
     * @param tag   A tag for storing/querying the result
     */
    public static void log(String tag)
    {
        if (BuildConfig.DEBUG || FORCE_PERFORMANCE_TRACKING)
        {
            double milliseconds = ((System.nanoTime() - tickingMap.get(tag)) / NANO_TIME_TO_MILLISECONDS);
            try
            {
                Log.i(TAG, tag + " needed " + milliseconds + " ms");
            }
            catch (RuntimeException re)
            {
                System.out.println(tag + " needed " + milliseconds + " ms");
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.08794718909710392, 'fraction_numerical': 0.009369676320272573, 'mean_word_length': 2.610299769408148, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '14257', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1337, 'n_words': 447}