Ruby memoization - Code with Jason
12-May-2022 1254
Memoization is a performance optimization technique.The idea with memoization is: “When a method invokes an expensive operation, don’t perform that operation each time the method is called. Instead, just invoke the expensive operation once, remember the answer, and use that answer from now on each time the method is called.”Below is an example that shows the benefit of memoization. The example is a class with two methods which both return the same result, but one is memoized and one is not.The expensive operation in the example takes one second to run. As you can see from the benchmark I performed, the memoized method is dramatically more performant than the un-memoized one.
Ruby memoization - Code with Jason #ruby #rubydeveloper #rubyonrails #memoization #Jason #code https://rubyonrails.ba/link/ruby-memoization-code-with-jason