I.Totally.Agree.Ensayia wrote:Lua lets you do quite a few more things with easy shortcuts than any other language. I really feel spoiled by it, it would probably be hard for me to start learning another language. There's no way C, C++, Java, etc would allow you to do something that elegant...
"Adding" a number to an variable
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: "Adding" a number to an variable
Re: "Adding" a number to an variable
What was wrong with the suggestion of just multiplying by 10 and adding the number?
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: "Adding" a number to an variable
It's very marginally faster to do the concat way (100,000 reps each comes to .066 seconds for the multiply and add, while it only took .044 for the concat).
But beyond that I dunno.
Source:
But beyond that I dunno.
Source:
Code: Select all
function love.load()
x = 0
sx = love.timer.getTime()
for i=1,100000 do
x = (x * 10) + 1
end
ex = love.timer.getTime()
y = 0
sy = love.timer.getTime()
for i=1,100000 do
y = tonumber(tostring(y).."1")
end
ey = love.timer.getTime()
end
function love.draw()
love.graphics.print("It took " .. (ex-sx) .. " to multiply x 100,000 times", 5, 5)
love.graphics.print("It took " .. (ey-sy) .. " to concatenate y 100,000 times", 5, 25)
end
Kurosuke needs beta testers
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 80 guests