Lua

For a project I'm working on, I'm learning Lua and I need to strengthen my Linux fu. The "Hello World" that I use for new languages is a count to a million. I use this because I have to have an output and a loop and it shows the speed of the language. In this case, I also included os.clock() which returns the time in seconds since the script started. Here is the script:

for n=1,1000000 do
print(n,os.clock())

end

I named it script.lua in Windows you just double click it(assuming you have Lua already installed)

It opens in what looks like a command prompt, after the script is done the window shuts immediately so you don't have time to read all the magical numbers. I added another loop and variable to keep it on the screen long enough for me to ogle it. That looks like this:

x=os.clock()
for o=1,10000000 do
print(x,os.clock())
end


In Linux it's a bit more complicated to run it. You type this into a terminal:

 lua -i script.lua

and it runs right in the terminal. I didn't have to add the extra code because it stays open.

Now for the interesting stuff!

My Windows 7 box:
8 core Amd
8GB ram
Script run time: 429.418 seconds- more than 7 minutes!

My headless Linux Mint 10 laptop:
2 core Pentium 4
512MB ram(video shared)
Script run time: 23.95 seconds- less than 7 minutes!

So in the time it took for my Linux computer to count to a million, my far more powerful Windows computer only made it to ~54000.

I don't know what cases such a vast difference, but there it is.




Comments

  1. Text output to the windows console is a really slow operation, while doing the same in Linux is quite faster.. Thats really about the architecture of the underlying OS.. If you want conclusive results for benchmarks, try doing other operations rather than a print :D

    ReplyDelete
  2. That comparison was a cursory glance meant to force me to implement the hello world on both OSes. I have since abandoned Lua.

    ReplyDelete

Post a Comment

Popular posts from this blog

Click Bait Using Logan Paul's Name and Face

Fate of the Furious Ending Scene