Skip to content

Commit

Permalink
test(gnovm): run initStaticBlocks in BenchmarkPreprocess (#2792)
Browse files Browse the repository at this point in the history
fixes #2711

The bug in the benchmark was introduced in #2418, which requires to run
initStaticBlocks before running Preprocess, in most cases. (in normal
scenarios, this is run by PredefineFileSet; however this benchmark is
deep into the internals).

Related: #2716. cc/ @sw360cab 

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
  • Loading branch information
thehowl authored Sep 16, 2024
1 parent 10228c4 commit 5503cca
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gnovm/pkg/gnolang/gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func BenchmarkIfStatement(b *testing.B) {
func main() {
for i:=0; i<10000; i++ {
if i > 10 {
}
}
}`
Expand Down Expand Up @@ -356,13 +356,16 @@ func BenchmarkPreprocess(b *testing.B) {
Inc("i"),
),
))
pn := NewPackageNode("hey", "gno.land/p/hey", nil)
copies := make([]*FuncDecl, b.N)
for i := 0; i < b.N; i++ {
copies[i] = main.Copy().(*FuncDecl)
}
b.ResetTimer()

for i := 0; i < b.N; i++ {
// initStaticBlocks is always performed before a Preprocess
initStaticBlocks(nil, pn, copies[i])
main = Preprocess(nil, pkg, copies[i]).(*FuncDecl)
}
}
Expand Down

0 comments on commit 5503cca

Please sign in to comment.