Giter VIP home page Giter VIP logo

setsuna's Introduction

Build Status Coverage Status

Setsuna

Setsuna is a tool for measuring the running time of a certain process for the Java programs.

Background

Problem of Previous Timer

Consider a typical measuring process in the conventional method. The measuring process is generally like below.

timer.start();
// essential process for measuring time.
....
timer.stop();
long time = timer.getTime();

The problem of the above program is that: start and stop method is not the essential process, however, the both method calls were beside the essential process. If a program has a much measuring processes, the essential process will be concealed, then it will be the cause of the confusion.

Our Solution

Basically

Therefore, Setsuna introduces lambda expressions, and functional interfaces in Java 8 platform, then measures the running time, like below.

RunningTime time = Timer.measure(() -> {
    // essential process for measuring time.
    ....
});

From the above program, the essential process will be in a block, we can eliminate start and stop method calls for measuring. The measured time is returned by an object of RunningTime.

Value returned process

Of course, Setsuna accepts the value returned process.

TimeredObject<SUITABLE_CLASS> object = Timer.measure(() -> {
    // essential process for measuring time.
    ....
    return hoge;
});

From the above program, when some value is returned in the block, measure method returns an object of TimeredObject. TimeredObject is just wrapper of RunningTime and returned value.

Exceptions

If the essential process will throw some Exception, we can use ThrowableTimer instead of Timer.

RunningTime time = ThrowableTimer.measure(() -> {
    // essential process for measuring time.
    ....
});
TimeredObject<SUITABLE_CLASS> object = ThrowableTimer.measure(() -> {
    // essential process for measuring time.
    ....
    return hoge;
});

Install

GitHub

  • Checkout the project from GitHub,
  • Change directory to the project,
  • Type mvn package,
    • If mvn was not found, install Maven.
  • setsuna-1.0-SNAPSHOT.jar will be packaged in target directory.
  • Add the jar file into your project, and measure the running time like above programs.

Setsuna

Setsuna はメソッドやJavaプログラムの実行時間を計測するツールです.

Background

Problem of Previous Timer

従来の実行時間計測は,プログラムを汚すものが多いと感じていました. 例えば,次のように.

timer.start();
// ここで何らかの本質的な処理
....
timer.stop();
long time = timer.getTime();

上記のプログラムだと,時間計測のためのstartstopは本質的な処理ではありません. にもかかわらず,本質的な処理に紛れてしまっています. 時間計測処理が多くなればなるほど,本質的な処理と計測のための処理が混ざり,混乱の元になります.

Our Solution

Basically

そこで,本プロジェクトでは,ラムダ式と関数型インターフェースを利用して,次のように処理時間を計測します.

RunningTime time = Timer.measure(() -> {
    // ここで何らかの本質的な処理
    ....
});

このように行うことで,本質的な処理をブロックに置き,計測のためのstartstop メソッドの呼び出しを不要にしています. ラムダ式の代わりに,適切なインターフェースを実装して,本質的な処理を別のクラスに抽出できます.

Value returned process

もちろん,返り値のあるプログラムであっても問題ありません.

TimeredObject<SUITABLE_CLASS> object = Timer.measure(() -> {
    // ここで何らかの本質的な処理
    ....
    return hoge;
});

上記のようにブロックの中で値を返すとtimer.measureTimeredObject を返します.TimeredObjectは単なる計測時間と返り値のラッパです.

Exceptions

ある処理が例外を投げる場合もTimerの代わりにThrowableTimerを利用することで計測可能です.

RunningTime time = ThrowableTimer.measure(() -> {
    // ここで何らかの本質的な処理
    ....
});
TimeredObject<?> object = ThrowableTimer.measure(() -> {
    // ここで何らかの本質的な処理
    ....
    return hoge;
});

Install

GitHub

  • GitHubからプロジェクトをチェックアウトしてください.
  • チェックアウトしてできたディレクトリに移動して,mvn packageを実行してください.
    • mvnが見つからない場合は,Maven を先にインストールしてください.
  • mvn packageが実行できれば,setsuna-1.0-SNAPSHOT.jartargetに作成されています.
  • 作成できたjarファイルをご自身のプロジェクトのクラスパスに追加して上記のようなプログラムで時間を計測してください.

setsuna's People

Contributors

tamada avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.