title: Why is lua on host system slower than in the linux vm?
body: <p>Comparing executing time of <a href="https://github.com/markuman/sumdata/blob/master/script-lang/sumdata.lua" rel="nofollow">this Lua Script</a> on a Macbook Air (Mac OS 10.9.4, i5-4250U (1.3GHz), 8GB RAM) to a VM (virtualbox) running Arch Linux.</p>
  
  <h2>Compiling Lua 5.2.3 in a Arch Linux virtualbox</h2>
  
  <p>First I've compiled lua by myself using clang, to compare it with the Mac OS X clang binary.</p>
  
  <h3>using tcc, gcc and clang</h3>
  
  <pre><code>$ tcc *[^ca].c lgc.c lfunc.c lua.c -lm -o luatcc
  $ gcc -O3 *[^ca].c lgc.c lfunc.c lua.c -lm -o luagcc
  /tmp/ccxAEYH8.o: In function `os_tmpname':
  loslib.c:(.text+0x29c): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
  $ clang -O3 *[^ca].c lgc.c lfunc.c lua.c -lm -o luaclang
  /tmp/loslib-bd4ef4.o:loslib.c:function os_tmpname: warning: the use of `tmpnam' is dangerous, better use `mkstemp'
  </code></pre>
  
  clang version in VM
  
  <pre><code>$ clang --version
  clang version 3.4.2 (tags/RELEASE_34/dot2-final)
  Target: x86_64-unknown-linux-gnu
  Thread model: posix
  </code></pre>
  
  <h3>compare the file size</h3>
  
  <pre><code>$ ls -lh |grep lua
  -rwxr-xr-x 1 markus markus 210K 20. Aug 18:21 luaclang
  -rwxr-xr-x 1 markus markus 251K 20. Aug 18:22 luagcc
  -rwxr-xr-x 1 markus markus 287K 20. Aug 18:22 luatcc
  </code></pre>
  
  <h2>VM benchmarking</h2>
  
  <h3>clang binary ~3.1 sec</h3>
  
  <pre><code>$ time ./luaclang sumdata.lua data.log
  Original Size: 117261680 kb
  Compressed Size: 96727557 kb
  real    0m3.124s
  user    0m3.100s
  sys  0m0.020s
  </code></pre>
  
  <h3>gcc binary ~3.09 sec</h3>
  
  <pre><code>$ time ./luagcc sumdata.lua data.log
  Original Size: 117261680 kb
  Compressed Size: 96727557 kb
  real    0m3.090s
  user    0m3.080s
  sys 0m0.007s
  </code></pre>
  
  <h3>tcc binary ~7.0 sec - no surprise here :)</h3>
  
  <pre><code>$ time ./luatcc sumdata.lua data.log
  Original Size: 117261680 kb
  Compressed Size: 96727557 kb
  real    0m7.071s
  user    0m7.053s
  sys 0m0.010s
  </code></pre>
  
  <h2>Compiling on Mac OS X</h2>
  
  <p>Now compiling lua with the same clang command/options like in the VM.</p>
  
  <pre><code>$ clang -O3 *[^ca].c lgc.c lfunc.c lua.c -lm -o luaclangmac
  loslib.c:108:3: warning: 'tmpnam' is deprecated: This function is provided for
  compatibility reasons only. Due to security concerns inherent in the design of tmpnam(3),
  it is highly recommended that you use mkstemp(3)
  instead. [-Wdeprecated-declarations]
  lua_tmpnam(buff, err);
  ^
  loslib.c:57:33: note: expanded from macro 'lua_tmpnam'
  #define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
  ^
  /usr/include/stdio.h:274:7: note: 'tmpnam' declared here
  char *tmpnam(char *);
  ^
  1 warning generated.
  </code></pre>
  
  clang version Mac OS X
  
  <p>I've tried two version. 3.4.2 and the one which is provided by xcode. The version 3.4.2 is a bit slower.</p>
  
  <pre><code>Markuss-MacBook-Air:bin markus$ ./clang --version
  clang version 3.4.2 (tags/RELEASE_34/dot2-rc1)
  Target: x86_64-apple-darwin13.3.0
  Thread model: posix
  Markuss-MacBook-Air:bin markus$ clang --version
  Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  Target: x86_64-apple-darwin13.3.0
  Thread model: posix
  </code></pre>
  
  <h3>file size</h3>
  
  <pre><code>$ ls -lh|grep lua
  -rwxr-xr-x 1 markus staff 194K 20 Aug 18:26 luaclangmac
  </code></pre>
  
  <h2>HOST benchmarking</h2>
  
  <h3>clang binary ~4.3 sec</h3>
  
  <pre><code>$ time ./luaclangmac sumdata.lua data.log
  Original Size: 117261680 kb
  Compressed Size: 96727557 kb
  real    0m4.338s
  user    0m4.264s
  sys 0m0.062s
  </code></pre>
  
  <h1>Why?</h1>
  
  <p>I would have expected that the host system is a little faster than the virtualization (or roughly the same speed). But not that the host system is reproducible slower.</p>
  
  <p>So, any ideas or explanations?</p>
  
  <h1>Update 2014.10.30</h1>
  
  <p>Meanwhile I've installed Arch Linux nativly on my MBA. The benchmarks are as fast as in the Arch Linux VM.</p>