GithubHelp home page GithubHelp logo

Comments (1)

rewinfrey avatar rewinfrey commented on September 25, 2024

Custom formatting can now be specified for benchmark logging (see this commit)

# Subclass ActionLogic::ActionBenchmark::DefaultFormatter
# This sets up a few things in the constructor and makes sure the correct log IO is provided via
# the `benchmark_log` attr_reader.
class CustomFormatter < ActionLogic::ActionBenchmark::DefaultFormatter

  # Custom formatters require you to define three methods (one for each of the ActionLogic execution 
  # context types (`ActionTask`, `ActionUseCase` and `ActionCoordinator`)
  # The respective methods your custom formatter will need to define are:
  # `def coordinator`, `def use_case` and `def task`

  # Each of the format methods receives two inputs: 
  # `benchmark_result` which is a Ruby stdlib Benchmark instance
  # `context_name` which is a Ruby String representing the class name of the `ActionTask`,   
  # `ActionUseCase`, `ActionCoordinator` or  class
  def task(benchmark_result, context_name)
    benchmark_log.puts("[task] #{context_name}: #{benchmark_result.real}")
  end

  def use_case(benchmark_result, context_name)
    benchmark_log.puts("[use case] #{context_name}: #{benchmark_result.real}")
  end

  def coordinator(benchmark_result, context_name)
    benchmark_log.puts("[coordinator] #{context_name}: #{benchmark_result.real}")
  end
end

# To configure ActionLogic to use your custom formatter, you'll need to specify a 
# few configuration options:
ActionLogic::ActionConfiguration.configure do |config|
  config.benchmark = true
  config.benchmark_log = File.open("tmp.log", "w") # If you do not specify a log file, stdout will be used
  config.benchmark_formatter = CustomFormatter
end

# Using this configuration with the test suite yields a benchmark output formatted like so:

SimpleTestTask: 3.322999691590667e-05
SimpleTestUseCase: 0.00011545396409928799
UseCaseTestTask1: 2.9074028134346008e-05
UseCaseTestTask2: 2.7913018129765987e-05
SimpleTestUseCase2: 0.00011622201418504119
SimpleTestTask: 6.190297426655889e-05
SimpleTestUseCase: 0.00018308503786101937
...

# If no custom formatter is defined, ActionLogic provides a default formatter
# whose output is a machine readable format for easy parsing:

context:   SimpleTestTask                                     user_time: 0.000000   system_time: 0.000000   total_time: 0.000000   real_time: 0.000048
context:   SimpleTestTask                                     user_time: 0.000000   system_time: 0.000000   total_time: 0.000000   real_time: 0.000030
context:   FailureTestTask                                    user_time: 0.000000   system_time: 0.000000   total_time: 0.000000   real_time: 0.000038
context:   ErrorHandlerTestTask                               user_time: 0.000000   system_time: 0.000000   total_time: 0.000000   real_time: 0.000042
context:   ValidateAroundCustomTypeTestTask                   user_time: 0.000000   system_time: 0.000000   total_time: 0.000000   real_time: 0.000044
context:   ValidateAroundTestTask                             user_time: 0.000000   system_time: 0.000000   total_time: 0.000000   real_time: 0.000164
...

from actionlogic.

Related Issues (10)

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.