summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-08-25 11:39:35 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-08-25 11:39:35 +0000
commitd34b8dca901083e5b68fd22899cb2c014238f8a4 (patch)
treee3f91aa170bc8c27729c6c406d3e20c7df97de0f
parentCached some functions (diff)
downloadinkscape-d34b8dca901083e5b68fd22899cb2c014238f8a4.tar.gz
inkscape-d34b8dca901083e5b68fd22899cb2c014238f8a4.zip
addes cache and log to a function, result of the test, no diference so remove cache on next commit
(bzr r13645.1.112)
-rw-r--r--src/helper/geom-satellite.cpp108
-rw-r--r--src/helper/geom-satellite.h7
-rw-r--r--src/live_effects/lpe-fillet-chamfer.cpp8
-rw-r--r--src/live_effects/lpe-fillet-chamfer.h1
4 files changed, 90 insertions, 34 deletions
diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp
index 35d21ef32..fac314b7f 100644
--- a/src/helper/geom-satellite.cpp
+++ b/src/helper/geom-satellite.cpp
@@ -15,6 +15,13 @@
#include <2geom/sbasis-to-bezier.h>
#include <2geom/ray.h>
#include <boost/optional.hpp>
+//log cache
+#ifdef _WIN32
+#include <Windows.h>
+#else
+#include <sys/time.h>
+#include <ctime>
+#endif
/**
* @brief Satellite a per ?node/curve holder of data.
@@ -39,6 +46,49 @@ Satellite::~Satellite() {}
* Calculate the time in curve_in with a size of A
* TODO: find a better place to it
*/
+
+//http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c
+/* Remove if already defined */
+typedef long long int64; typedef unsigned long long uint64;
+
+/* Returns the amount of milliseconds elapsed since the UNIX epoch. Works on both
+ * windows and linux. */
+
+uint64 GetTimeMs64()
+{
+#ifdef _WIN32
+ /* Windows */
+ FILETIME ft;
+ LARGE_INTEGER li;
+
+ /* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and copy it
+ * to a LARGE_INTEGER structure. */
+ GetSystemTimeAsFileTime(&ft);
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+
+ uint64 ret = li.QuadPart;
+ ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */
+ ret /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */
+
+ return ret;
+#else
+ /* Linux */
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+
+ uint64 ret = tv.tv_usec;
+ /* Convert from micro seconds (10^-6) to milliseconds (10^-3) */
+ ret /= 1000;
+
+ /* Adds the seconds (10^0) after converting them to milliseconds (10^-3) */
+ ret += (tv.tv_sec * 1000);
+
+ return ret;
+#endif
+}
+
double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit)
{
if ( A == 0 || curve_in.isDegenerate()) {
@@ -47,19 +97,34 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache
//using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast-
Geom::D2<Geom::SBasis> d2_in = curve_in.toSBasis();
- static std::deque<std::pair<double, std::pair<double, Geom::D2<Geom::SBasis> > > > deque_cache;
- if(cache_limit > 0 && deque_cache.size() > cache_limit){
- std::deque<std::pair<double, std::pair<double, Geom::D2<Geom::SBasis> > > > deque_cache_split(deque_cache.begin(), deque_cache.begin() + cache_limit);
- deque_cache = deque_cache_split;
+
+ static bool cached = false;
+ if(cache_limit == 0){
+ cached = false;
+ } else if(cache_limit > 1){
+ cached = true;
}
- if(cache_limit > 0){
+ static size_t count = 0;
+ static uint64 start = GetTimeMs64();
+ static uint64 time_diff = GetTimeMs64();
+ static cache_item cache_value = std::make_pair(0.0, std::make_pair(A, d2_in));
+ if(cache_limit > 1 || cache_limit == 0){
+ uint64 end = GetTimeMs64();
+ uint64 elapsed_ms = end-start;
+ if(count == 0){
+ time_diff = 0;
+ } else if(elapsed_ms < 1000){
+ time_diff += elapsed_ms;
+ }
+ std::cout << "counter:" << count << ", cached:" << cached << ", function:timeAtArcLength" << ", miliseconds:" << elapsed_ms << ", acumulated ms:" << time_diff << "\n";
+ start = end;
+ count++;
return 1;
}
- std::deque<std::pair<double, std::pair<double, Geom::D2<Geom::SBasis> > > >::iterator it;
- for (it = deque_cache.begin() ; it != deque_cache.end(); ++it){
- if(it->second.first == A){
- if(it->second.second == d2_in){
- return it->first;
+ if(cached){
+ if(cache_value.second.first == A){
+ if(cache_value.second.second == d2_in ){
+ return cache_value.first;
}
}
}
@@ -77,7 +142,9 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache
t = t_roots[0];
}
}
- deque_cache.push_front(std::make_pair(t, std::make_pair(A, d2_in)));
+ if(cached){
+ cache_value = std::make_pair(t, std::make_pair(A, d2_in));
+ }
return t;
}
@@ -85,7 +152,7 @@ double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache
* Calculate the size in curve_in with a point at A
* TODO: find a better place to it
*/
-double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_limit)
+double arcLengthAt(double const A, Geom::Curve const &curve_in)
{
if ( A == 0 || curve_in.isDegenerate()) {
return 0;
@@ -93,22 +160,6 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_lim
//using "d2_in" for curve comparation, using directly "curve_in" crash in bezier compare function- dynamic_cast-
Geom::D2<Geom::SBasis> d2_in = curve_in.toSBasis();
- static std::deque<std::pair<double, std::pair<double, Geom::D2<Geom::SBasis> > > > deque_cache;
- if(cache_limit > 0 && deque_cache.size() > cache_limit){
- std::deque<std::pair<double, std::pair<double, Geom::D2<Geom::SBasis> > > > deque_cache_split(deque_cache.begin(), deque_cache.begin() + cache_limit);
- deque_cache = deque_cache_split;
- }
- if(cache_limit > 0){
- return 1;
- }
- std::deque<std::pair<double, std::pair<double, Geom::D2<Geom::SBasis> > > >::iterator it;
- for (it = deque_cache.begin() ; it != deque_cache.end(); ++it){
- if(it->second.first == A){
- if(it->second.second == d2_in){
- return it->first;
- }
- }
- }
double s = 0;
double length_part = curve_in.length();
if (A > length_part || curve_in.isLineSegment()) {
@@ -117,7 +168,6 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_lim
Geom::Curve *curve = curve_in.portion(0.0, A);
s = curve->length();
}
- deque_cache.push_front(std::make_pair(s, std::make_pair(A, d2_in)));
return s;
}
diff --git a/src/helper/geom-satellite.h b/src/helper/geom-satellite.h
index ed1ec221b..61ac6be75 100644
--- a/src/helper/geom-satellite.h
+++ b/src/helper/geom-satellite.h
@@ -27,7 +27,7 @@ enum SatelliteType {
/**
* @brief Satellite a per ?node/curve holder of data.
*/
-
+typedef std::pair<double, std::pair<double, Geom::D2<Geom::SBasis> > > cache_item;
class Satellite {
public:
@@ -87,8 +87,9 @@ public:
double angle;
size_t steps;
};
-double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit = 0);
-double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_limit = 0);
+//cache_limit never called as 1
+double timeAtArcLength(double const A, Geom::Curve const &curve_in, size_t cache_limit = 1);
+double arcLengthAt(double const A, Geom::Curve const &curve_in);
#endif // SEEN_SATELLITE_H
diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp
index 3fa011b38..a83c7bbd5 100644
--- a/src/live_effects/lpe-fillet-chamfer.cpp
+++ b/src/live_effects/lpe-fillet-chamfer.cpp
@@ -55,6 +55,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject)
"ignore_radius_0", &wr, this, false),
helper_size(_("Helper size with direction:"),
_("Helper size with direction"), "helper_size", &wr, this, 0),
+ cache(_("Cache size:"),_("Cache size"), "cache_size", &wr, this, 3),
pointwise(NULL)
{
registerParameter(&satellites_param);
@@ -68,6 +69,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject)
registerParameter(&ignore_radius_0);
registerParameter(&only_selected);
registerParameter(&hide_knots);
+ registerParameter(&cache);
radius.param_set_range(0.0, Geom::infinity());
radius.param_set_increments(1, 1);
@@ -78,6 +80,9 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject)
helper_size.param_set_range(0, 999);
helper_size.param_set_increments(5, 5);
helper_size.param_set_digits(0);
+ cache.param_set_range(0, 999);
+ cache.param_set_increments(1, 1);
+ cache.param_set_digits(0);
}
void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem)
@@ -380,8 +385,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem)
Geom::Curve const &first_curve = pathv.curveAt(0);
size_t number_curves = pathv.curveCount();
//Activete cache
- timeAtArcLength(1, first_curve, number_curves * 3);
- arcLengthAt(1, first_curve, number_curves * 3);
+ timeAtArcLength(1, first_curve, number_curves * cache);
for (std::vector<Satellite>::iterator it = sats.begin();
it != sats.end();) {
if (it->is_time != flexible) {
diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h
index 804709342..9c58ab66c 100644
--- a/src/live_effects/lpe-fillet-chamfer.h
+++ b/src/live_effects/lpe-fillet-chamfer.h
@@ -58,6 +58,7 @@ private:
BoolParam hide_knots;
BoolParam ignore_radius_0;
ScalarParam helper_size;
+ ScalarParam cache;
Pointwise *pointwise;
Geom::PathVector _hp;