<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><p id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; margin: 0px; line-height: auto;">I was working on some code today and encountered this scenario here where the performance behavior of data.table surprised me a little. Is this expected?</p><p id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; margin: 0px; line-height: auto;"><br></p><p id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; margin: 0px; line-height: auto;"><p id="bloop_customfont" style="margin: 0px; ">> dt = data.table(a=rnorm(1000000))</p><p id="bloop_customfont" style="margin: 0px; "><p id="bloop_customfont" style="margin: 0px; "><br></p><p id="bloop_customfont" style="margin: 0px; ">> system.time( for(i in 1:100000) j = dt[i, a] )</p><p id="bloop_customfont" style="margin: 0px; ">  usuário   sistema decorrido </p><p id="bloop_customfont" style="margin: 0px; ">   78.064     0.426    78.034 </p><p id="bloop_customfont" style="margin: 0px; "><br></p></p><p id="bloop_customfont" style="margin: 0px; "><p id="bloop_customfont" style="margin: 0px; ">> system.time( for(i in 1:100000) j = dt[i, "a", with=F] )</p><p id="bloop_customfont" style="margin: 0px; ">  usuário   sistema decorrido </p><p id="bloop_customfont" style="margin: 0px; ">   27.814     0.154    27.810</p><p id="bloop_customfont" style="margin: 0px; "> </p><p id="bloop_customfont" style="margin: 0px; ">> system.time( for(i in 1:100000) j = dt[["a"]][i] )</p><p id="bloop_customfont" style="margin: 0px; ">  usuário   sistema decorrido </p><p id="bloop_customfont" style="margin: 0px; ">    1.227     0.006     1.225 </p></p></p><div><br></div><div>(sorry about the output in portuguese)</div><div><br></div><div>Not knowing anything about how data.table is implemented internally, I would have assumed the three syntaxes for accessing the data.table should have similar or at the most a small difference in performance.</div><div><br></div><div id="bloop_sign_1369761945473322752"><span style="font-family:helvetica,arial;font-size:13px"></span><div style="font-family: Helvetica; line-height: normal; ">-- </div><div style="font-family: Helvetica; line-height: normal; "><span style="font-family: arial; font-size: small; ">Alexandre Sieira</span><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">CISA, CISSP, ISO 27001 Lead Auditor</span><br style="font-family: arial; font-size: small; "><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">"The truth is rarely pure and never simple."</span><br style="font-family: arial; font-size: small; "><span style="font-family: arial; font-size: small; ">Oscar Wilde, The Importance of Being Earnest, 1895, Act I</span></div></div></body></html>