This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
augustas656's profile picture

Computer Speed Test (Hertz Meassurements)

Started by augustas656, 28 April 2014 - 08:41 PM
augustas656 #1
Posted 28 April 2014 - 10:41 PM
Computer Speed Test

Hertz & Ticks


This is a program used to measure your computers speed, it checks how many cycles it can perform (+1 calculations) in a tick, it repeats this for 20 times, making a whole second's waiting time, then it finds the average mean of these 20 results, and writes it in form of hertz, megahertz, gigahertz and ticks. Ticks are the raw form, hertz are ticks multiplied by 20, and kilo and mega hertz are 1000x bigger than the prior. This program also provides the raw data in hertz form, which is a 20x form of ticks. 20 ticks a second, 1 cycle in a second is 1 hertz. To turn off the program you press ENTER then your clean clears.

Graphical User Interface:
Spoiler
Pastebin Link: http://pastebin.com/SzFZixBk

Compatability:
  • Works with both Advanced and Basic computers, supports their colour existance and not.
  • It prints out things directly on specific areas, cropping the screen to a size where text is trying to be written where impossible it won't work.
  • Should work with all (real-life) computer speeds.
Possible Future Changes:
  • Options to store the results in many different ways.
  • Options to compare stored results, or test twice and compare them.
  • Options to remove stored results.
Changelog:
  • Fixed megahertz and gigahertz to kilohertz and megahertz as they were incorrect measure labels for the actual value of cycles.

Regards
Augustas
Edited on 28 April 2014 - 10:09 PM
electrodude512 #2
Posted 28 April 2014 - 11:56 PM
Nice, but it has some problems. A megahertz is 1,000,000Hz, not 1,000Hz. A gigahertz is 1,000,000,000Hz, not 1,000,000Hz. You're only getting 0.94 megahertz, not gigahertz. The majority of the time in your increment look is probably spent checking the clock. If you put the cycles = cycles + 1 in a for loop that went 100 times, you would lose 2 digits of precision (which would be made up for by the average) but would (probably) get significantly higher results. You should also do more samples for more accurate results.

Another serious problem is that you could get an inaccurate result if a clock tick is about to or just has happened. You should sit in a look waiting for the clock to change before starting your count.

function test()
  local cycles = 0
  local time = os.clock()
  while time == os.clock() do end  -- wait for time to change, then it will be time+0.05
  time = time + 0.1  --it must be time+0.05 now because it used to be time but the clock changed, we want to wait for time+0.1, which is a delta of 0.05
  while os.clock()<time do
    for i = 1, 100 do  -- do 100 cycles every check - it's extremely unlikely that the time changed (1/1000000 chance), so why even check?
	  cycles = cycles + 1
    end
  end
  return cycles/0.05    --  (cycles) cycles per (0.05 seconds = 1 tick)
end

local avg, lastavg = 0, 0
local n = 100
local lastsleep = os.clock()
for i = 1, n do
  lastavg = test()
  avg = avg + lastavg
  print(lastavg/1000000 .. "MHz this test, " .. avg/i/1000000 .. "MHz average")
  if lastsleep+3<os.clock() then -- sleep every so often (every 3 seconds) to avoid too long without yielding
    sleep(0) -- bad practice but whatever
    lastsleep = os.clock()
  end
end
avg = avg / n
print()
print(avg/1000000 .. "MHz average")

I got 6-12MHz (whether or not I was doing anything else) with this code under an old version of cc-emu with a bunch of other programs open. Your code only got 0.5MHz (what you called GHz). I never realized how slow LuaJ was. You can use my code if you want, or you could just copy the changes into your own. I only showed MHz, not kHz or plain old Hz, but your program has them which is nice.

Hope that didn't sound too critical, I didn't mean to be.

electrodude512
Edited on 28 April 2014 - 09:57 PM
augustas656 #3
Posted 29 April 2014 - 12:03 AM
I got the Mhz &amp; Ghz mixed up with Khz and Mhz, I'm gonna fix that right now.
I've done this on minecraft rather than CC-EMU, it's only useful for comparisons because the results can be random because it's trying to run it's fastest, it can be pretty random, and the size of the result isn't very important if you're just making comparisons. You aren't waiting 0.1 seconds between each function you call, it runs it's fastest and delays as accurately to the specified amount as possible.

I've fixed it, it's kilo and mega.

Regards
Augustas
Edited on 28 April 2014 - 10:10 PM