POV-Ray : Newsgroups : povray.general : Function performance : Re: Function performance Server Time
29 Jul 2024 12:21:45 EDT (-0400)
  Re: Function performance  
From: Alain
Date: 5 Aug 2011 14:14:10
Message: <4e3c32f2@news.povray.org>
Le 2011/08/04 18:00, clipka a écrit :

>
> My favorite solution to such issues is to replace, e.g.,
>
> #declare F = function(a) { sin(a) + cos(a) + sin(a)*cos(a) }
>
> with
>
> #declare F_ = function(sina,cosa) { sina + cosa + sina*cosa }
> #declare F = function(a) { F_(sin(a),cos(a)) }
>
> The idea is to create a helper function where all the multiply-used
> sub-expressions are substituted by parameters, and have a main function
> that computes these sub-expressions and passes them to that helper
> function. I think it's sufficiently easy to read if you use good names
> for the sub-expressions.
>

You are probably also geting some performance improvement that way: The 
sin() and cos() functions are now only evaluated once, then you pass the 
returned values to the helper function.



Alain


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.