Skip to content

Commit

Permalink
Added a Frame per second benchmark metric
Browse files Browse the repository at this point in the history
Measure of FPS can now be displayed as long as experiment
provides a frame_count() member.
  • Loading branch information
jfalcou committed Mar 26, 2014
1 parent 6b21358 commit a0694f2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
3 changes: 3 additions & 0 deletions demo/sigmadelta/nt2/sigmadelta_nt2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <iostream>

#include <nt2/sdk/bench/benchmark.hpp>
#include <nt2/sdk/bench/metric/fps.hpp>
#include <nt2/sdk/bench/metric/cycles_per_element.hpp>
#include <nt2/sdk/bench/protocol/max_duration.hpp>
#include <nt2/sdk/bench/setup/geometric.hpp>
Expand Down Expand Up @@ -110,6 +111,7 @@ template<typename T> struct sigmadelta_nt2
}

std::size_t size() const { return size_ * nb_frames; }
std::size_t frame_count() const { return nb_frames; }

private:
std::size_t height;
Expand All @@ -136,5 +138,6 @@ NT2_REGISTER_BENCHMARK( sigmadelta_nt2 )
, geometric(wmin,wmax,wstep)
)
, cycles_per_element<stats::median_>()
, fps<stats::median_>()
);
}
9 changes: 6 additions & 3 deletions demo/sigmadelta/scalar/sigmadelta_scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <iostream>

#include <nt2/sdk/bench/benchmark.hpp>
#include <nt2/sdk/bench/metric/fps.hpp>
#include <nt2/sdk/bench/metric/cycles_per_element.hpp>
#include <nt2/sdk/bench/protocol/max_duration.hpp>
#include <nt2/sdk/bench/setup/geometric.hpp>
Expand Down Expand Up @@ -107,6 +108,7 @@ template<typename T> struct sigmadelta_scalar
}

std::size_t size() const { return size_ * nb_frames; }
std::size_t frame_count() const { return nb_frames; }

private:
std::size_t height;
Expand All @@ -128,12 +130,13 @@ NT2_REGISTER_BENCHMARK( sigmadelta_scalar )
std::size_t wmax = args("wmax", 128);
std::size_t wstep = args("wstep", 2);

run_during_with< sigmadelta_scalar<nt2::uint8_t> > ( 1.
run_during_with< sigmadelta_scalar<nt2::uint8_t> >( 1.
, and_( constant( frame )
, geometric(hmin,hmax,hstep)
, geometric(wmin,wmax,wstep)
)
, cycles_per_element<stats::median_>()
);
, cycles_per_element<stats::median_>()
, fps<stats::median_>()
);
}

5 changes: 4 additions & 1 deletion demo/sigmadelta/simd/sigmadelta_simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <nt2/sdk/bench/benchmark.hpp>
#include <nt2/sdk/bench/protocol/max_duration.hpp>
#include <nt2/sdk/bench/metric/fps.hpp>
#include <nt2/sdk/bench/metric/cycles_per_element.hpp>
#include <nt2/sdk/bench/stats/median.hpp>
#include <nt2/sdk/bench/setup/geometric.hpp>
Expand Down Expand Up @@ -123,7 +124,8 @@ struct sigmadelta_simd
return os << "(" << p.height << " x " << p.width << " @" << p.nb_frames << ")";
}

std::size_t size() const { return size_ * nb_frames; }
std::size_t size() const { return size_ * nb_frames; }
std::size_t frame_count() const { return nb_frames; }

private:
std::size_t height;
Expand All @@ -150,5 +152,6 @@ NT2_REGISTER_BENCHMARK( sigmadelta_simd )
, geometric(wmin,wmax,wstep)
)
, cycles_per_element<stats::median_>()
, fps<stats::median_>()
);
}
53 changes: 53 additions & 0 deletions modules/test/benchmark/include/nt2/sdk/bench/metric/fps.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//==============================================================================
// Copyright 2009 - 2013 LRI UMR 8623 CNRS/Univ Paris Sud XI
// Copyright 2012 - 2014 MetaScale SAS
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#ifndef NT2_SDK_BENCH_METRIC_FPS_HPP_INCLUDED
#define NT2_SDK_BENCH_METRIC_FPS_HPP_INCLUDED

#include <nt2/sdk/bench/details/compute_stat.hpp>
#include <nt2/sdk/bench/details/measure.hpp>
#include <nt2/sdk/bench/metric/speedup.hpp>
#include <nt2/sdk/timing/now.hpp>
#include <string>

namespace nt2 { namespace bench
{
/*!
@brief Frames per second metric
This metric calculates the FPS of a benchmark.
@tparam Stat Statistic to compute over the provided samples
**/
template<typename Stat> struct fps
{
/// @brief Evaluation of the metric in GFLOPS
template<typename Experiment> inline
double operator() ( Experiment const& e
, std::string const& name
, nt2::details::times_set const& t
, nt2::details::cycles_set const&
) const
{
typedef typename details::compute_state<Stat>::type sc_t;

double m = e.frame_count() / (sc_t::evaluate(t) * 1e-6);
details::measures_map[details::identify_result(name,e,*this)] = m;

return m;
}

/// @brief Metric display
inline std::string unit() const
{
return "FPS" + Stat::unit();
}
};
} }

#endif

0 comments on commit a0694f2

Please sign in to comment.