diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-08-21 00:28:52 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-08-21 13:18:28 -0600 |
commit | 6b1fcde7af64ca81079dffe1d62096228693b5d6 (patch) | |
tree | 2600ece91b5179105a572d79b60a6fc07e82c0a7 | |
parent | 4f9a96f6cdee4cf234bde7fdafd0be0f5b6b808e (diff) | |
download | dimension-6b1fcde7af64ca81079dffe1d62096228693b5d6.tar.xz |
Don't dynamically allocate timers.
-rw-r--r-- | dimension/dimension.in | 4 | ||||
-rw-r--r-- | libdimension-python/dimension.pxd | 9 | ||||
-rw-r--r-- | libdimension-python/dimension.pyx | 20 | ||||
-rw-r--r-- | libdimension/dimension/scene.h | 4 | ||||
-rw-r--r-- | libdimension/dimension/timer.h | 18 | ||||
-rw-r--r-- | libdimension/raytrace.c | 8 | ||||
-rw-r--r-- | libdimension/scene.c | 7 | ||||
-rw-r--r-- | libdimension/timer.c | 17 |
8 files changed, 26 insertions, 61 deletions
diff --git a/dimension/dimension.in b/dimension/dimension.in index f0db4fc..cfebe78 100644 --- a/dimension/dimension.in +++ b/dimension/dimension.in @@ -161,7 +161,7 @@ if not _args.quiet: parse_timer = Timer() with open(_args.input) as _fh: exec(compile(_fh.read(), _args.input, "exec")) -parse_timer.complete() +parse_timer.stop() # Make the canvas canvas = Canvas(width = _args.region_width, height = _args.region_height) @@ -203,7 +203,7 @@ _progress_bar(render_message, scene.raytrace_async()) # Write the output file export_timer = Timer() _progress_bar("Writing %s" % _args.output, canvas.write_PNG_async(_args.output)) -export_timer.complete() +export_timer.stop() # Print execution times if _args.verbose: diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd index a3523d0..7b3ba6e 100644 --- a/libdimension-python/dimension.pxd +++ b/libdimension-python/dimension.pxd @@ -84,9 +84,8 @@ cdef extern from "../libdimension/dimension.h": double user double system - dmnsn_timer *dmnsn_new_timer() - void dmnsn_complete_timer(dmnsn_timer *timer) - void dmnsn_delete_timer(dmnsn_timer *timer) + void dmnsn_start_timer(dmnsn_timer *timer) + void dmnsn_stop_timer(dmnsn_timer *timer) ############ # Geometry # @@ -392,8 +391,8 @@ cdef extern from "../libdimension/dimension.h": double adc_bailout unsigned int nthreads - dmnsn_timer *bounding_timer - dmnsn_timer *render_timer + dmnsn_timer bounding_timer + dmnsn_timer render_timer dmnsn_scene *dmnsn_new_scene() void dmnsn_delete_scene(dmnsn_scene *scene) diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx index 0c0c214..d0bd4e7 100644 --- a/libdimension-python/dimension.pyx +++ b/libdimension-python/dimension.pyx @@ -87,7 +87,7 @@ cdef _Progress(dmnsn_progress *progress): cdef class Timer: """A timer for Dimension tasks.""" - cdef dmnsn_timer *_timer + cdef dmnsn_timer _timer def __init__(self): """ @@ -95,14 +95,11 @@ cdef class Timer: Timing starts as soon as the object is created. """ - self._timer = dmnsn_new_timer() + dmnsn_start_timer(&self._timer) - def __dealloc__(self): - dmnsn_delete_timer(self._timer) - - def complete(self): + def stop(self): """Stop the Timer.""" - dmnsn_complete_timer(self._timer) + dmnsn_stop_timer(&self._timer) property real: """Real (wall clock) time.""" @@ -121,10 +118,9 @@ cdef class Timer: return "%.2fs (user: %.2fs; system: %.2fs)" % \ (self._timer.real, self._timer.user, self._timer.system) -cdef _Timer(dmnsn_timer *timer): +cdef _Timer(dmnsn_timer timer): cdef Timer self = Timer.__new__(Timer) self._timer = timer - DMNSN_INCREF(self._timer) return self ############ @@ -1450,16 +1446,10 @@ cdef class Scene: property bounding_timer: """The Timer for building the bounding hierarchy.""" def __get__(self): - if self._scene.bounding_timer == NULL: - raise RuntimeError("scene has not been rendered yet") - return _Timer(self._scene.bounding_timer) property render_timer: """The Timer for the actual render.""" def __get__(self): - if self._scene.render_timer == NULL: - raise RuntimeError("scene has not been rendered yet") - return _Timer(self._scene.render_timer) def raytrace(self): diff --git a/libdimension/dimension/scene.h b/libdimension/dimension/scene.h index 2f659e9..c35f91f 100644 --- a/libdimension/dimension/scene.h +++ b/libdimension/dimension/scene.h @@ -76,8 +76,8 @@ typedef struct dmnsn_scene { unsigned int nthreads; /** Timers. */ - dmnsn_timer *bounding_timer; - dmnsn_timer *render_timer; + dmnsn_timer bounding_timer; + dmnsn_timer render_timer; bool initialized; /**< @internal Whether the scene is initialized. */ } dmnsn_scene; diff --git a/libdimension/dimension/timer.h b/libdimension/dimension/timer.h index bd72a90..6bffce6 100644 --- a/libdimension/dimension/timer.h +++ b/libdimension/dimension/timer.h @@ -28,8 +28,6 @@ typedef struct dmnsn_timer { double real; /**< Wall-clock time. */ double user; /**< Time spent executing. */ double system; /**< Time spent waiting for the system. */ - - dmnsn_refcount refcount; /**< @internal Reference count. */ } dmnsn_timer; /** A standard format string for timers. */ @@ -41,22 +39,16 @@ typedef struct dmnsn_timer { * @endcode * will print something like "1.00s (user: 0.99s; system: 0.01s)". */ -#define DMNSN_TIMER_PRINTF(t) (t)->real, (t)->user, (t)->system +#define DMNSN_TIMER_PRINTF(t) (t).real, (t).user, (t).system /** - * Create a new timer. Timing starts right before this function returns. - * @return A new timer object. + * Start a timer. The values of an unfinished timer are undefined. + * @param[in,out] timer The timer to start. */ -dmnsn_timer *dmnsn_new_timer(void); +void dmnsn_start_timer(dmnsn_timer *timer); /** * Finish timing. The members of the timer struct will now contain timing data. * @param[in,out] timer The timer to stop. */ -void dmnsn_complete_timer(dmnsn_timer *timer); - -/** - * Delete a timer. - * @param[in,out] timer The timer to delete. - */ -void dmnsn_delete_timer(dmnsn_timer *timer); +void dmnsn_stop_timer(dmnsn_timer *timer); diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 71e5578..92947d6 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -80,18 +80,18 @@ dmnsn_raytrace_scene_thread(void *ptr) dmnsn_initialize_scene(payload->scene); /* Time the bounding tree construction */ - payload->scene->bounding_timer = dmnsn_new_timer(); + dmnsn_start_timer(&payload->scene->bounding_timer); payload->prtree = dmnsn_new_prtree(payload->scene->objects); - dmnsn_complete_timer(payload->scene->bounding_timer); + dmnsn_stop_timer(&payload->scene->bounding_timer); /* Set up the progress object */ dmnsn_set_progress_total(payload->progress, payload->scene->canvas->height); /* Time the render itself */ - payload->scene->render_timer = dmnsn_new_timer(); + dmnsn_start_timer(&payload->scene->render_timer); int ret = dmnsn_execute_concurrently(dmnsn_raytrace_scene_concurrent, payload, payload->scene->nthreads); - dmnsn_complete_timer(payload->scene->render_timer); + dmnsn_stop_timer(&payload->scene->render_timer); dmnsn_delete_prtree(payload->prtree); dmnsn_free(payload); diff --git a/libdimension/scene.c b/libdimension/scene.c index f0ff451..dc62799 100644 --- a/libdimension/scene.c +++ b/libdimension/scene.c @@ -48,8 +48,6 @@ dmnsn_new_scene(void) scene->reclimit = 5; scene->adc_bailout = 1.0/255.0; scene->nthreads = dmnsn_ncpus(); - scene->bounding_timer = NULL; - scene->render_timer = NULL; scene->initialized = false; return scene; @@ -60,9 +58,6 @@ void dmnsn_delete_scene(dmnsn_scene *scene) { if (scene) { - dmnsn_delete_timer(scene->render_timer); - dmnsn_delete_timer(scene->bounding_timer); - DMNSN_ARRAY_FOREACH (dmnsn_light **, light, scene->lights) { dmnsn_delete_light(*light); } @@ -84,7 +79,7 @@ dmnsn_delete_scene(dmnsn_scene *scene) void dmnsn_initialize_scene(dmnsn_scene *scene) { - dmnsn_assert(!scene->initialized, "Texture double-initialized."); + dmnsn_assert(!scene->initialized, "Scene double-initialized."); scene->initialized = true; if (scene->outer_width == 0) { diff --git a/libdimension/timer.c b/libdimension/timer.c index ad0fd9b..e0873a8 100644 --- a/libdimension/timer.c +++ b/libdimension/timer.c @@ -25,17 +25,14 @@ #include "dimension-impl.h" -dmnsn_timer * -dmnsn_new_timer(void) +void +dmnsn_start_timer(dmnsn_timer *timer) { - dmnsn_timer *timer = dmnsn_malloc(sizeof(dmnsn_timer)); dmnsn_get_times(timer); - timer->refcount = 1; - return timer; } void -dmnsn_complete_timer(dmnsn_timer *timer) +dmnsn_stop_timer(dmnsn_timer *timer) { dmnsn_timer now; dmnsn_get_times(&now); @@ -43,11 +40,3 @@ dmnsn_complete_timer(dmnsn_timer *timer) timer->user = now.user - timer->user; timer->system = now.system - timer->system; } - -void -dmnsn_delete_timer(dmnsn_timer *timer) -{ - if (DMNSN_DECREF(timer)) { - dmnsn_free(timer); - } -} |