jmchich

OpenOS SHA-256 speedtest

Jan 8th, 2021
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. --[[
  2.   Simple program to find out the speed of making sha256 hashes in OpenOS (OpenComputers Minecraft mod's OS)
  3.   using Tier 3 Data card and IgorTimofeev's SHA-256 library (https://raw.githubusercontent.com/IgorTimofeev/MineOS/master/Libraries/SHA-256.lua)
  4.   My results are 0.47 and 3.9 for Data Card and Lib, respectively
  5.   P.S. Sorry for bad lua code, I'm new to this
  6. --]]
  7.  
  8. s = require('SHA-256')
  9. component = require('component')
  10.  
  11. function AddZeroes(x, n)
  12.     local p = tostring(x)
  13.     while string.len(p) < n do
  14.         p = "0" .. p
  15.     end
  16.     return p
  17. end
  18.  
  19. function GetLastI(n)
  20.     local p = ""
  21.     for i = 1, n do
  22.         p = p .. "9"
  23.     end
  24.     local x = tonumber(p)
  25.     return x
  26. end
  27.  
  28. function string.tohex(str)
  29.     return (str:gsub('.', function (c)
  30.         return string.format('%02X', string.byte(c))
  31.     end))
  32. end
  33.  
  34. data = component.data
  35.  
  36. local x = os.clock()
  37. for a=1, 3 do
  38.     for b=0, GetLastI(a) do
  39.         p = AddZeroes(b,a)
  40.         d = p .. ":" .. string.lower(string.tohex(data.sha256(p)))
  41.         os.sleep(0)
  42.     end
  43. end
  44. print("Using datacard: " .. os.clock() - x)
  45.  
  46. local x = os.clock()
  47. for a=1, 3 do
  48.   for b=0, GetLastI(a) do
  49.     p = AddZeroes(b,a)
  50.     d = p .. ":" .. s.hash(p)
  51.     os.sleep(0)
  52.   end
  53. end
  54. print("Using library: " .. os.clock() - x)
Advertisement
Add Comment
Please, Sign In to add comment