All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cloudbus.cloudsim.util.ExecutionTimeMeasurer Maven / Gradle / Ivy

Go to download

CloudSim Plus: A modern, highly extensible and easier-to-use Java 8 Framework for Modeling and Simulation of Cloud Computing Infrastructures and Services

There is a newer version: 8.0.0
Show newest version
/*
 * Title:        CloudSim Toolkit
 * Description:  CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 *
 * Copyright (c) 2009-2012, The University of Melbourne, Australia
 */

package org.cloudbus.cloudsim.util;

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

/**
 * Measurement of execution times of CloudSim's methods.
 *
 * @author Anton Beloglazov
 * @since CloudSim Toolkit 3.0
 */
public final class ExecutionTimeMeasurer {

    /**
     * A map of execution start times where each key
     * represents the name of the method/process and each key is the
     * time the method/process started (in milliseconds).
     * Usually, this name is the method/process name, making
     * it easy to identify the execution start times into the map.
     */
    private static final Map EXECUTION_START_TIMES = new HashMap<>();

    /**
     * A private constructor to avoid class instantiation.
     */
    private ExecutionTimeMeasurer(){}

    /**
     * Starts measuring the execution time of a method/process.
     * Usually this method has to be called at the first line of the method
     * that has to be its execution time measured.
     *
     * @param name the name of the method/process being measured.
     * @see #getExecutionStartTimes()
     */
    public static void start(final String name) {
        EXECUTION_START_TIMES.put(name, System.currentTimeMillis());
    }

    /**
     * Finalizes measuring the execution time of a method/process.
     *
     * @param name the name of the method/process being measured.
     * @return the time the method/process spent in execution (in seconds)
     * @see #getExecutionStartTimes()
     */
    public static double end(final String name) {
        return (System.currentTimeMillis() - EXECUTION_START_TIMES.remove(name)) / 1000.0;
    }

    /**
     * Gets the map of execution times.
     *
     * @return the execution times map
     * @see #EXECUTION_START_TIMES
     */
    static Map getExecutionStartTimes() {
        return EXECUTION_START_TIMES;
    }

    /**
     * Gets the execution start time
     *
     * @param name the name of the method/process to get the execution start time
     * @return the execution start time for the the given method/process
     * @see #EXECUTION_START_TIMES
     */
    static Long getExecutionStartTime(final String name){
        return EXECUTION_START_TIMES.get(name);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy