Note that there are some explanatory texts on larger screens.

plurals
  1. POBenchmarking: using `expression` `quote` or neither
    primarykey
    data
    text
    <p>Generally, when I run benchmarks, I wrap my statements in <code>expression</code>. Recently, it was suggested to either (a) not do so or (b) use <code>quote</code> instead of expression. </p> <p>I find two advantages to wrapping the statements: </p> <ul> <li>compared to entire statements, they are more easily swapped out. </li> <li>I can lapply over a list of inputs, and compare those results</li> </ul> <p>However, in exploring the different methods, I noticed a discrepency between the three methods (wrapping in <code>expression</code>, wrapping in <code>quote</code>, or not wrapping at all) </p> <p><strong>The question is:</strong><br> Why the discrepency? <BR> (it appears that wrapping in <code>quote</code> does not actually evaluate the call.)</p> <h2>EXAMPLE:</h2> <pre><code># SAMPLE DATA mat &lt;- matrix(sample(seq(1e6), 4^2*1e4, T), ncol=400) # RAW EXPRESSION TO BENCHMARK IS: # apply(mat, 2, mean) # WRAPPED EXPRESSION: expr &lt;- expression(apply(mat, 2, mean)) quot &lt;- quote(apply(mat, 2, mean)) # BENCHMARKS benchmark(raw=apply(mat, 2, mean), expr, quot)[, -(7:8)] # test replications elapsed relative user.self sys.self # 2 expr 100 1.269 NA 1.256 0.019 # 3 quot 100 0.000 NA 0.001 0.000 # 1 raw 100 1.494 NA 1.286 0.021 # BENCHMARKED INDIVIDUALLY benchmark(raw=apply(mat, 2, mean))[, -(7:8)] benchmark(expr)[, -(7:8)] benchmark(quot)[, -(7:8)] # results # test replications elapsed relative user.self sys.self # 1 raw 100 1.274 1 1.26 0.018 # test replications elapsed relative user.self sys.self # 1 expr 100 1.476 1 1.342 0.021 # test replications elapsed relative user.self sys.self # 1 quot 100 0.006 1 0.006 0.001 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload