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

com.github.bogdanovmn.common.log.Duration Maven / Gradle / Ivy

The newest version!
package com.github.bogdanovmn.common.log;

import com.github.bogdanovmn.humanreadablevalues.MillisecondsValue;
import lombok.extern.slf4j.Slf4j;

import java.util.function.Supplier;

@Slf4j
public class Duration {
    private Duration() {
    }

    public static  T log(String description, Supplier supplier) {
        long start = System.currentTimeMillis();
        T result = supplier.get();
        log.info(
            String.format(
                "%s took %s",
                    description,
                    new MillisecondsValue(System.currentTimeMillis() - start).shortString()
            )
        );
        return result;
    }

    public static long inMills(Runnable task) {
        long start = System.currentTimeMillis();
        task.run();
        return System.currentTimeMillis() - start;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy