generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Fahrenheit to Celsius.

Previous Thread :: Next Thread 
m00dventure is not online. m00dventure
Joined: 03 Aug 2011
Total Posts: 75
06 Aug 2011 08:36 PM
I made a converter of fahrenheit to celsius, Its there:

function convert(fahrenheit)
a = fahrenheit - 32
print(a / 1.8)
end

convert(70)
Report Abuse
MyrcoAlt is not online. MyrcoAlt
Joined: 31 Mar 2011
Total Posts: 209
06 Aug 2011 08:46 PM
Too late.
Report Abuse
pokelover980 is not online. pokelover980
Joined: 12 Jun 2009
Total Posts: 4141
06 Aug 2011 08:49 PM
More efficient:

local function convert(fahrenheit)
local a = fahrenheit - 32
return a / 1.8
end

print(convert(70))

Even more efficient:

local function convert(fahrenheit)
return (fahrenheit - 32) / 1.8
end
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
06 Aug 2011 09:25 PM
Pokelover, I doubt your second example is more efficient when measuring runtime.
Report Abuse
blocco is not online. blocco
Joined: 14 Aug 2008
Total Posts: 29474
06 Aug 2011 09:27 PM
@Necro: It should be, because the interpreter doesn't have to take the time to set the variable "a".
Report Abuse
jode6543 is not online. jode6543
Joined: 16 Jun 2009
Total Posts: 5363
06 Aug 2011 09:43 PM
@Blocco I think the point he was getting at that the change is so small it has almost no effect.

-Jode
Report Abuse
pokelover980 is not online. pokelover980
Joined: 12 Jun 2009
Total Posts: 4141
06 Aug 2011 09:50 PM
@Necro:

local function convert1(fahrenheit)
local a = fahrenheit - 32
return a / 1.8
end

local function convert2(fahrenheit)
return (fahrenheit - 32) / 1.8
end

local t = os.clock()
for i = 1, 10000000 do
convert1(70)
end
print(os.clock() - t)
local t = os.clock()
for i = 1, 10000000 do
convert2(70)
end
print(os.clock() - t)

Using the regular Lua VM (too lazy to test LuaJIT), the second one is faster by ~0.011s on average doing that many iterations. Sure, it's not a lot, and no one would realistically be doing that many iterations for any normal reason, but it's still faster.
Report Abuse
Aaaboy97 is not online. Aaaboy97
Joined: 05 Apr 2009
Total Posts: 6612
06 Aug 2011 09:51 PM
If you're going for better speed, remember that multiplication is faster than division, but if you use multiplication, you're going to have to lose some accuracy.

local c = (f - 32)*0.55555555555556
Report Abuse
pokelover980 is not online. pokelover980
Joined: 12 Jun 2009
Total Posts: 4141
06 Aug 2011 09:58 PM
@Aaaboy: In my opinion, do things as fast as possible while doing it as accurate as possible. Though multiplication does yield a bit faster, it's ~0.05 seconds faster than each of the previous tests I posted if you replace the division with multiplication.
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
07 Aug 2011 09:56 AM
The only real difference between them being the local keyword, the VM would have to keep track of that register as being local, and the second example might use one less register, but who knew that would have an 11 millisecond delay o_O.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image