Precompute some values of a function

raphaelchinchilla
Wed, 01 Jun 2022 19:28:09 +0000
Performance

Consider the following MWE:

d=rand(10^8);
f(x,d) = x + sum(d)
g(x) = f(x,d)

If I run @benchmark f(1,d) and @benchmark g(1) (in the REPL), both take the same amount of time to run (which is what I kind of excepted). Is there a way to write a function equivalent to g(x) to run as fast as the sum of two float points? I am thinking that maybe using macros could work because they are evaluated at parse time instead of execution time, but I don’t know how to do it.

8 posts - 5 participants