-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58dca3b
commit d2043e1
Showing
3 changed files
with
49 additions
and
1 deletion.
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
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
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,32 @@ | ||
(env-gasmodel "table") | ||
(env-gaslimit 1000000) | ||
|
||
; Define an expensive function, which we will use to test memoization. | ||
(module m g | ||
(defcap g () true) | ||
(defun go(n:integer) "Do an expensive computation" | ||
(let ((xs (enumerate 1 n)) | ||
(fn (lambda (a b) (+ a b)))) | ||
(fold (fn) 0 xs) | ||
))) | ||
|
||
; We will test memoization by checking that gas usage is lower | ||
; for a memo table hit than for a miss. | ||
(env-gas 0) | ||
(m.go 10) | ||
(expect "Executing unmemoized function costs gas" 36 (env-gas)) | ||
|
||
(env-memoize (m.go 10)) | ||
(env-gas 0) | ||
(m.go 10) | ||
(expect "Executing memoized function is cheap" 0 (env-gas)) | ||
|
||
|
||
(env-gas 0) | ||
(shift 10 (shift 1 1)) | ||
(expect "Executing unmemoized native costs gas" 3 (env-gas)) | ||
|
||
(env-memoize (shift 10 (shift 1 1))) | ||
(env-gas 0) | ||
(shift 10 2) | ||
(expect "Executing memoized native is cheap" 0 (env-gas)) |