- Home /
What's faster: Lerp or LerpUnclamped? (Performance)
In terms of performance, what's faster: Mathf.Lerp or Mathf.LerpUnclamped? Also asking about Vector3.Lerp / LerpUnclamped.
I tried running some tests on my end but my own results were pretty inconclusive, so if one IS faster I suspect the difference is pretty small. Still, I'd love to know definitively which one is faster.
Thanks!
Answer by landon912 · May 26, 2017 at 01:05 AM
Implementation Details:
Lerp:
public static float Lerp(float a, float b, float t)
{
return a + (b - a) * Mathf.Clamp01(t);
}
LerpUnclamped:
public static float LerpUnclamped(float a, float b, float t)
{
return a + (b - a) * t;
}
Therefore, LerpUnclamped is in theory faster than Lerp. But really, a function call and two double comparisons is nothing to be sweating over. As you said, your timed tests likely show as negligible.
Thank you! Yeah, that explains why my own test (run a for loop a bunch of times) didn't really show a difference. Cheers :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612122818im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Performance gain through recycling Objects? 1 Answer
What's a good draw call count? 2 Answers
Android Best performance 1 Answer
Need optimizing tips for mobile third person shooting game. 2 Answers
Frame Drop on Touching or Swiping Screen 0 Answers