lua-users home
lua-l archive

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


Given that Lua is an interpreted language, conventional wisdom dictates
that it's most likely going to spend most of its time doing instruction
decodes rather than actual work. Therefore, the fewer the instructions
the better --- no matter what the instructions do.

I want to implement a priority queue. I have two possible strategies
when inserting an item:

(a) binary chop through the array until I find the place to insert the
item, then call table.insert to do it.

(b) append the item at the end of the array and then use table.qsort to
sort the entire array.

(a) involves the least amount of theoretical work. (b) involves the
fewest number of actual instructions. So, which one is faster? And is
the answer still true when using LuaJit?

(Right now I'm going for (b) --- since I can implement it in three lines
of Lua.)

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup

Attachment: signature.asc
Description: OpenPGP digital signature