lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Luiz Henrique de Figueiredo wrote:
Trouble is, does this pattern ever appear in normal code? I find it difficult to believe that calling a function that returns a function to be called, and so on, chained in this manner, could happen in real-world code.

Similar code is generated in chains of messages to objects, such as
	o:a():b():c()

Several libraries return the object as the result of messages to allow
this kind of chaining.

The above needs SELF to set up the stack for the CALLs, while Alexander's example has LOADK to set up parameters for each CALL. I guess I had a little trouble trying to compare the benchmarks by trying to see them as comparisons of real-world calls.

Like some of the others who commented, I often look at Alexander's benchmarks and end up mentally trying to gauge the cost of a MOVE or a GETUPVAL. It did not quite struck me as a comparison of real-world call patterns, as the code has been stripped down into a microbenchmark. If we were comparing real-world call patterns, we would need to compare

  cat "one" "two" "four" "five"

versus

  cat "one"
  cat "two"
  cat "four"
  cat "five"

rather than chain()()()()()(). We then get to see the performance difference set against the overall performance of "real" calls in operation. Seeing the timing delta is useful, but I would choose a more realistic rendition of the absolute timing for each case over an artificial one.

So my problem was really a case of wondering "what am I really getting out of this benchmark?" But I do like both microbenchmarks and real-world benchmarks, always nice seeing real data.

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia