github.com/ontio/ontology@v1.14.4/vm/neovm/executor_test.go (about) 1 /* 2 * Copyright (C) 2018 The ontology Authors 3 * This file is part of The ontology library. 4 * 5 * The ontology is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Lesser General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * The ontology is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with The ontology. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 package neovm 20 21 import ( 22 "testing" 23 24 "github.com/ontio/ontology/vm/neovm/types" 25 ) 26 27 func BenchmarkNewExecutor(b *testing.B) { 28 code := []byte{byte(PUSH1)} 29 30 N := 50000 31 for i := 0; i < N; i++ { 32 code = append(code, byte(PUSH1), byte(ADD)) 33 } 34 35 for i := 0; i < b.N; i++ { 36 exec := NewExecutor(code, VmFeatureFlag{}) 37 err := exec.Execute() 38 if err != nil { 39 panic(err) 40 } 41 val, err := exec.EvalStack.PopAsIntValue() 42 if err != nil { 43 panic(err) 44 } 45 if val != types.IntValFromInt(int64(N+1)) { 46 panic("wrong result") 47 } 48 } 49 } 50 51 func BenchmarkNative(b *testing.B) { 52 53 N := 50000 54 55 for i := 0; i < b.N; i++ { 56 sum := 0 57 for j := 0; j < N; j++ { 58 sum += 1 59 } 60 } 61 }