sergkh

Untitled

Oct 6th, 2021
866
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --------------------------------------------------
  2. --  CPU Benchmarking Functions
  3. --------------------------------------------------
  4. function GetSystemTimeSeconds()
  5.    local socket = require "socket"
  6.    return socket.gettime()*1000
  7. end  
  8. function CPUBenchmark()
  9.     --This function gives the CPU some busy work to do.
  10.    --CPU score is determined by how quickly the work is completed.
  11.    print("test")
  12.     local totalTime = 0
  13.     local lastTime
  14.     local currTime
  15.     local countTime = 0
  16.     --Make everything a local variable
  17.     --This is necessary because we don't want LUA searching through the globals as part of the benchmark
  18.     local TableInsert = table.insert
  19.     local TableRemove = table.remove
  20.     local h
  21.     local i
  22.     local j
  23.     local k
  24.     local l
  25.     local m
  26.     local n = {}
  27.     for h = 1, 24, 1 do
  28.         -- If the need for the benchmark no longer exists, abort it now.
  29. --        if not lobbyComm then
  30. --            return
  31. --        end
  32.  
  33.         lastTime = GetSystemTimeSeconds()
  34. --  print(lastTime)
  35.         for i = 1.0, 30.4, 0.0008 do
  36.            --This instruction set should cover most LUA operators
  37.             j = i + i   --Addition
  38.             k = i * i   --Multiplication
  39.             l = k / j   --Division
  40.             m = j - i   --Subtraction
  41.             j = i ^ 4   --Power
  42.             l = -i      --Negation
  43.             m = {'1234567890', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', true} --Create Table
  44.             TableInsert(m, '1234567890')     --Insert Table Value
  45.             k = i < j   --Less Than
  46.             k = i == j  --Equality
  47.             k = i <= j  --Less Than or Equal to
  48.             k = not k
  49.             n[tostring(i)] = m
  50.         end
  51.         currTime = GetSystemTimeSeconds()
  52.         totalTime = totalTime + currTime - lastTime
  53.  
  54.         if totalTime > countTime then
  55.             --This is necessary in order to make this 'thread' yield so other things can be done.
  56.             countTime = totalTime + .125
  57. --            coroutine.yield(1)
  58.         end
  59.     end
  60.     BenchTime = math.ceil(totalTime )
  61.     print(BenchTime)
  62.     return  BenchTime
  63.    
  64. end
  65. print(CPUBenchmark())
  66.  
RAW Paste Data