-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add cpu-cycle-overrun1.txtar . See the PR.
Signed-off-by: Jeff Thompson <jeff@thefirst.org>
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
loadpkg gno.land/p/demo/avl | ||
|
||
# start a new node | ||
gnoland start | ||
|
||
gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/cpu_cycle_overrun1 -gas-fee 1ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1 | ||
stdout OK! | ||
|
||
# Call AddData 3 times | ||
gnokey maketx call -pkgpath gno.land/r/cpu_cycle_overrun1 -func AddData -gas-fee 1ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1 | ||
stdout OK! | ||
gnokey maketx call -pkgpath gno.land/r/cpu_cycle_overrun1 -func AddData -gas-fee 1ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1 | ||
stdout OK! | ||
gnokey maketx call -pkgpath gno.land/r/cpu_cycle_overrun1 -func AddData -gas-fee 1ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1 | ||
stdout OK! | ||
|
||
# Call AddData one more time. The call to Render hangs. If you comment this out, then the call to Render returns quickly. | ||
gnokey maketx call -pkgpath gno.land/r/cpu_cycle_overrun1 -func AddData -gas-fee 1ugnot -gas-wanted 100000000 -broadcast -chainid=tendermint_test test1 | ||
stdout OK! | ||
|
||
# Call Render | ||
gnokey query vm/qrender --data "gno.land/r/cpu_cycle_overrun1\n" | ||
|
||
-- cpu_cycle_overrun1.gno -- | ||
package cpu_cycle_overrun1 | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
"gno.land/p/demo/avl" | ||
) | ||
|
||
var gData = avl.Tree{} // id -> string | ||
|
||
type MyData struct { | ||
data avl.Tree | ||
} | ||
|
||
// Add a lot of data to gData (as much as we can do with the given maximum gas allowed). | ||
func AddData() { | ||
for i := 1; i <= 1000; i++ { | ||
gData.Set(strconv.Itoa(gData.Size()), "hello") | ||
} | ||
} | ||
|
||
func Render(path string) string { | ||
// Put the data in allData. | ||
subdata := &MyData{data: gData} | ||
allData := avl.Tree{} | ||
gData.Iterate("", "", func(key string, postI interface{}) bool { | ||
allData.Set(strconv.Itoa(allData.Size()), subdata) | ||
return false | ||
}) | ||
|
||
// Iterate allData and make the render string. | ||
now := time.Now() | ||
str := "" | ||
allData.Iterate("", "", func(key string, dataI interface{}) bool { | ||
str += now.Format("2006-01-02 3:04pm MST") | ||
return false | ||
}) | ||
return "len " + strconv.Itoa(len(str)) | ||
} |