Jump to content




How fast is a computer?


4 replies to this topic

#1 hugeblank

  • Members
  • 122 posts
  • LocationA grocery store near you!

Posted 28 November 2015 - 11:30 AM

So I know that minecraft runs at 20 ticks per second, is that how fast a computer in CC runs? Except of course, in lines. So 20 lines per second.



#2 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 28 November 2015 - 11:54 AM

Lets dispel some common myths: Minecraft runs at 20 ticks per second. ComputerCraft does not. ComputerCraft runs on a separate thread and so is not bound by how fast Minecraft is running.

So, if it isn't running at 20 instructions/lines/whatevers per second, how fast is it? CC uses LuaJ which uses an interpreter: this is just lots of if statements which look your code and decides what to do next, consequently this is pretty slow. However, most of the time this is fast enough - most programs are not doing computationally intensive tasks.

Sometimes even the best optimised programs will be slightly too slow, but there isn't really much we can do about that (we've tried implementing a Lua to Java compiler but there are still some problems with it - though if you fancy a read have a look here and here).

Edited by SquidDev, 28 November 2015 - 11:54 AM.


#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 28 November 2015 - 02:27 PM

In short, the execution speed of ComputerCraft computer boils down to the horsepower of the physical system running the Minecraft server. Interpreted languages may be inefficient, but when you get right down to it, modern hardware can easily take up the slack. To give a practical example, on my laptop Command Computers can read blocks from, or write blocks into, a Minecraft world at about two and a half thousand blocks per second (and that limit has more to do with the rate at which the world can handle the data - ComputerCraft has to stop and wait for it to catch up!).

There are at least a couple of caveats, however:

First off, time measurement. This is tied to the Minecraft tick rate - os.clock() always rounds to the nearest 20th of a second, and os.startTimer() always generates its events on the closest server tick. So while it's quite possible to execute loads of instructions per second, if for whatever reason you need to tie them to the clock, you can't measure time more finely than that. It's also worth bearing in mind that Minecraft can't properly handle redstone state changes that occur faster than every tenth of a second.

Secondly, only one system in a world can execute code at a time. If you have a turtle and a computer both running scripts at once, then ComputerCraft will have one system execute code while the other is yielding, and then perhaps switch control when the first one yields. Notably, this means that distributed processing is quite pointless within ComputerCraft.

Systems yield so frequently (to pull events: eg to get info on keypresses / turtle movements / timers / etc), and execution between yields is so fast, that this process is unnoticeable to the average user. Say you've got a whole bunch of computers turned on and simply running the default shell - they'll all just sit there and yield, waiting for users to type something (they'd use less server RAM if you turned them off (Ctrl + S), but it's still not a huge overall load). Once you get enough systems running processor-intensive code, however, you'll start to see computers around the world slowing down.

Edited by Bomb Bloke, 28 November 2015 - 02:29 PM.


#4 hugeblank

  • Members
  • 122 posts
  • LocationA grocery store near you!

Posted 28 November 2015 - 11:10 PM

Ok, that makes sense, so, if the physical system is controlling how fast it is, how can you determine the speed of the system? Is there an easy way to find out?

#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 28 November 2015 - 11:22 PM

local t = os.time()
local i = 0
while os.time() == t do i = i + 1 end
print( "An arbitrary number: " .. i )






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users