github.com/aergoio/aergo@v1.3.1/contract/measure/aef.lua (about) 1 loop_cnt = 1000 2 arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 } 3 tbl = { name= "kslee", year= 1981, age= 41, 4 name1= "kslee", year1= 1981, age1= 41, 5 name2= "kslee", year2= 1981, age2= 41, 6 xxx= true} 7 8 local print = function(...) 9 system.print(...) 10 end 11 12 local copy_arr = function(arr) 13 local a = {} 14 for i, v in ipairs(arr) do 15 a[i] = v 16 end 17 return a 18 end 19 20 function measure(fn, ...) 21 local start = nsec() 22 fn(...) 23 return nsec() - start 24 end 25 26 function m1k(fn, ...) 27 local r1k = function(fn) 28 return function(...) 29 for i = 1, loop_cnt do 30 fn(...) 31 end 32 end 33 end 34 t = measure(r1k(fn), ...) 35 print(string.format('%.9f', t / loop_cnt)) 36 end 37 38 function print_chain(fn) 39 return function(...) 40 print(fn(...)) 41 end 42 end 43 44 function m1kp(fn, ...) 45 m1k(print_chain(fn), ...) 46 end 47 48 function system_fns() 49 print("sysem.getSender") 50 m1k(system.getSender) 51 print("system.getBlockheight") 52 m1k(system.getBlockheight) 53 print("system.getTxhash") 54 m1k(system.getTxhash) 55 print("system.getTimestamp") 56 m1k(system.getTimestamp) 57 print("system.getContractID") 58 m1k(system.getContractID) 59 print("system.setItem") 60 m1k(system.setItem, "key100", "100ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd") 61 m1k(system.setItem, "key200", "200ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd") 62 m1k(system.setItem, "key400", "400ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd") 63 print("system.getItem") 64 m1k(system.getItem, "key100") 65 m1k(system.getItem, "key200") 66 m1k(system.getItem, "key400") 67 print("system.getAmount") 68 m1k(system.getAmount) 69 print("system.getCreator") 70 m1k(system.getCreator) 71 print("system.Origin") 72 m1k(system.getOrigin) 73 print("system.getPrevBlockHash") 74 m1k(system.getPrevBlockHash) 75 end 76 77 --TODO 78 function contract_fns() 79 end 80 81 local s100 = "100aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 82 local s200 = "200aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 83 local s400 = "400aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 84 85 function json_fns() 86 print("json.encode") 87 m1k(json.encode, 1) 88 m1k(json.encode, 100) 89 m1k(json.encode, 10000000000) 90 m1k(json.encode, 3.14159) 91 m1k(json.encode, 300000000.14159) 92 m1k(json.encode, s100) 93 m1k(json.encode, s200) 94 m1k(json.encode, s400) 95 m1k(json.encode, arr) 96 local long_arr100 = {} 97 for i = 1, 100 do 98 long_arr100[i] = i 99 end 100 m1k(json.encode, long_arr100) 101 local long_arr1000 = {} 102 for i = 1, loop_cnt do 103 long_arr1000[i] = i 104 end 105 m1k(json.encode, long_arr1000) 106 m1k(json.encode, tbl) 107 print("json.decode") 108 m1k(json.decode, json.encode(1)) 109 m1k(json.decode, json.encode(100)) 110 m1k(json.decode, json.encode(10000000000)) 111 m1k(json.decode, json.encode(3.14)) 112 m1k(json.decode, json.encode(300000000.14159)) 113 m1k(json.decode, json.encode(s100)) 114 m1k(json.decode, json.encode(s200)) 115 m1k(json.decode, json.encode(s400)) 116 m1k(json.decode, json.encode(arr)) 117 m1k(json.decode, json.encode(long_arr100)) 118 m1k(json.decode, json.encode(long_arr1000)) 119 m1k(json.decode, json.encode(tbl)) 120 end 121 122 function crypto_fns() 123 print("crypto.sha256") 124 m1k(crypto.sha256, "0x616200e490aa") 125 m1k(crypto.sha256, s100) 126 m1k(crypto.sha256, s200) 127 m1k(crypto.sha256, s400) 128 print("crypto.ecverify") 129 m1k(crypto.ecverify, "11e96f2b58622a0ce815b81f94da04ae7a17ba17602feb1fd5afa4b9f2467960", "304402202e6d5664a87c2e29856bf8ff8b47caf44169a2a4a135edd459640be5b1b6ef8102200d8ea1f6f9ecdb7b520cdb3cc6816d773df47a1820d43adb4b74fb879fb27402", "AmPbWrQbtQrCaJqLWdMtfk2KiN83m2HFpBbQQSTxqqchVv58o82i") 130 end 131 132 function bignum_fns() 133 print("bignum.number") 134 local nines = "999999999999999999999999999999" 135 local nines1 = "999999999" 136 local nines2 = 999999999 137 local one = 1 138 local b = 3.14e19 139 local pi = 3.14 140 local pi1 = 3.141592653589 141 m1k(bignum.number, nines) 142 m1k(bignum.number, nines1) 143 m1k(bignum.number, nines2) 144 m1k(bignum.number, one) 145 m1k(bignum.number, b) 146 m1k(bignum.number, pi) 147 m1k(bignum.number, pi1) 148 local nines_b = bignum.number(nines) 149 local nines1_b = bignum.number(nines1) 150 local nines2_b = bignum.number(nines2) 151 local one_b = bignum.number(one) 152 local b_b = bignum.number(b) 153 local pi_b = bignum.number(pi) 154 local pi1_b = bignum.number(pi1) 155 print("bignum.isneg") 156 m1k(bignum.isneg, nines_b) 157 m1k(bignum.isneg, nines1_b) 158 m1k(bignum.isneg, nines2_b) 159 m1k(bignum.isneg, one_b) 160 m1k(bignum.isneg, b_b) 161 m1k(bignum.isneg, pi_b) 162 m1k(bignum.isneg, pi1_b) 163 print("bignum.iszero") 164 m1k(bignum.iszero, nines_b) 165 m1k(bignum.iszero, nines1_b) 166 m1k(bignum.iszero, nines2_b) 167 m1k(bignum.iszero, one_b) 168 m1k(bignum.iszero, b_b) 169 m1k(bignum.iszero, pi_b) 170 m1k(bignum.iszero, pi1_b) 171 print("bignum.tonumber") 172 m1k(bignum.tonumber, nines_b) 173 m1k(bignum.tonumber, nines1_b) 174 m1k(bignum.tonumber, nines2_b) 175 m1k(bignum.tonumber, one_b) 176 m1k(bignum.tonumber, b_b) 177 m1k(bignum.tonumber, pi_b) 178 m1k(bignum.tonumber, pi1_b) 179 print("bignum.tostring") 180 m1k(bignum.tostring, nines_b) 181 m1k(bignum.tostring, nines1_b) 182 m1k(bignum.tostring, nines2_b) 183 m1k(bignum.tostring, one_b) 184 m1k(bignum.tostring, b_b) 185 m1k(bignum.tostring, pi_b) 186 m1k(bignum.tostring, pi1_b) 187 print("bignum.neg") 188 m1k(bignum.neg, nines_b) 189 m1k(bignum.neg, nines1_b) 190 m1k(bignum.neg, nines2_b) 191 m1k(bignum.neg, one_b) 192 m1k(bignum.neg, b_b) 193 m1k(bignum.neg, pi_b) 194 m1k(bignum.neg, pi1_b) 195 print("bignum.sqrt") 196 m1k(bignum.sqrt, nines_b) 197 m1k(bignum.sqrt, nines1_b) 198 m1k(bignum.sqrt, nines2_b) 199 m1k(bignum.sqrt, one_b) 200 m1k(bignum.sqrt, b_b) 201 m1k(bignum.sqrt, pi_b) 202 m1k(bignum.sqrt, pi1_b) 203 print("bignum.compare") 204 m1k(bignum.compare, one_b, one_b) 205 m1k(bignum.compare, nines_b, one_b) 206 m1k(bignum.compare, nines_b, nines_b) 207 m1k(bignum.compare, pi_b, pi_b) 208 m1k(bignum.compare, pi1_b, pi1_b) 209 m1k(bignum.compare, pi1_b, one_b) 210 m1k(bignum.compare, pi_b, one_b) 211 print("bignum.add") 212 m1k(bignum.add, one_b, one_b) 213 m1k(bignum.add, nines_b, one_b) 214 m1k(bignum.add, nines_b, nines_b) 215 m1k(bignum.add, pi_b, pi_b) 216 m1k(bignum.add, pi_b, pi1_b) 217 m1k(bignum.add, pi_b, one_b) 218 m1k(bignum.add, pi_b, nines_b) 219 m1k(bignum.add, pi1_b, one_b) 220 print("bignum.sub") 221 m1k(bignum.sub, one_b, one_b) 222 m1k(bignum.sub, bignum.number(-1), one_b) 223 m1k(bignum.sub, nines_b, one_b) 224 m1k(bignum.sub, nines_b, nines_b) 225 m1k(bignum.sub, nines_b, b_b) 226 m1k(bignum.sub, pi_b, nines_b) 227 m1k(bignum.sub, pi1_b, nines_b) 228 print("bignum.mul") 229 m1k(bignum.mul, one_b, one_b) 230 m1k(bignum.mul, bignum.number(-1), one_b) 231 m1k(bignum.mul, nines_b, one_b) 232 m1k(bignum.mul, nines_b, nines1_b) 233 m1k(bignum.mul, nines_b, nines_b) 234 m1k(bignum.mul, pi_b, one_b) 235 m1k(bignum.mul, pi_b, nines_b) 236 m1k(bignum.mul, pi_b, pi_b) 237 m1k(bignum.mul, pi1_b, pi1_b) 238 print("bignum.div") 239 m1k(bignum.div, one_b, one_b) 240 m1k(bignum.div, bignum.number(-1), one_b) 241 m1k(bignum.div, nines_b, one_b) 242 m1k(bignum.div, nines_b, nines_b) 243 m1k(bignum.div, nines_b, bignum.number(333)) 244 m1k(bignum.div, pi1_b, bignum.number(1)) 245 m1k(bignum.div, pi_b, pi1_b) 246 print("bignum.mod") 247 m1k(bignum.mod, one_b, one_b) 248 m1k(bignum.mod, bignum.number(-1), one_b) 249 m1k(bignum.mod, nines_b, one_b) 250 m1k(bignum.mod, nines_b, nines1_b) 251 m1k(bignum.mod, nines_b, bignum.number(333)) 252 m1k(bignum.mod, bignum.number(333), nines_b) 253 m1k(bignum.mod, nines1_b, bignum.number(333)) 254 m1k(bignum.mod, bignum.number(333), nines1_b) 255 m1k(bignum.mod, pi1_b, pi_b) 256 m1k(bignum.mod, pi1_b, one_b) 257 print("bignum.pow") 258 m1k(bignum.pow, one_b, one_b) 259 m1k(bignum.pow, bignum.number(-1), one_b) 260 m1k(bignum.pow, nines_b, one_b) 261 m1k(bignum.pow, nines_b, bignum.number(3)) 262 m1k(bignum.pow, nines_b, bignum.number(9)) 263 m1k(bignum.pow, nines1_b, bignum.number(3)) 264 m1k(bignum.pow, nines1_b, bignum.number(9)) 265 m1k(bignum.pow, pi1_b, one_b) 266 m1k(bignum.pow, pi1_b, pi_b) 267 m1k(bignum.pow, pi1_b, pi1_b) 268 print("bignum.divmod") 269 m1k(bignum.divmod, one_b, one_b) 270 m1k(bignum.divmod, bignum.number(-1), one_b) 271 m1k(bignum.divmod, nines_b, one_b) 272 m1k(bignum.divmod, nines_b, nines1_b) 273 m1k(bignum.divmod, bignum.number(3), nines_b) 274 m1k(bignum.divmod, bignum.number(9), nines_b) 275 m1k(bignum.divmod, bignum.number(3), nines1_b) 276 m1k(bignum.divmod, bignum.number(9), nines1_b) 277 m1k(bignum.divmod, pi1_b, pi_b) 278 m1k(bignum.divmod, pi1_b, pi1_b) 279 m1k(bignum.divmod, pi1_b, one_b) 280 print("bignum.powmod") 281 m1k(bignum.powmod, one_b, one_b, bignum.number(3)) 282 m1k(bignum.powmod, bignum.number(-1), one_b, bignum.number(3)) 283 m1k(bignum.powmod, nines_b, one_b, bignum.number(3)) 284 m1k(bignum.powmod, nines_b, bignum.number(3), bignum.number(4)) 285 m1k(bignum.powmod, nines_b, bignum.number(9), bignum.number(4)) 286 m1k(bignum.powmod, nines1_b, bignum.number(3), bignum.number(4)) 287 m1k(bignum.powmod, nines1_b, bignum.number(9), bignum.number(4)) 288 m1k(bignum.powmod, pi_b, bignum.number(9), bignum.number(4)) 289 m1k(bignum.powmod, pi1_b, bignum.number(9), bignum.number(4)) 290 end 291 292 function run_test() 293 system_fns() 294 json_fns() 295 crypto_fns() 296 bignum_fns() 297 end 298 299 abi.register(run_test) 300