annotate caching-tests/bench.ur @ 2290:ab6ca12debeb

Add small benchmark (WIP).
author ziv@mit.edu
date Sun, 15 Nov 2015 18:10:24 -0500
parents
children 23eaec04e0f8
rev   line source
ziv@2290 1 table tab : {Id : int, Val : int} PRIMARY KEY Id
ziv@2290 2
ziv@2290 3 fun check id =
ziv@2290 4 res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]});
ziv@2290 5 return <xml><body>
ziv@2290 6 {case res of
ziv@2290 7 None => <xml>?</xml>
ziv@2290 8 | Some row => <xml>{[row.Tab.Val]}</xml>}
ziv@2290 9 </body></xml>
ziv@2290 10
ziv@2290 11 fun flush id =
ziv@2290 12 dml (UPDATE tab SET Val = Val + 1 WHERE Id = {[id]});
ziv@2290 13 return <xml><body>
ziv@2290 14 Changed {[id]}!
ziv@2290 15 </body></xml>
ziv@2290 16
ziv@2290 17 fun main x y =
ziv@2290 18 r <- rand;
ziv@2290 19 let
ziv@2290 20 val id = r % x
ziv@2290 21 val doFlush = (r / x) % y = 0
ziv@2290 22 in
ziv@2290 23 if doFlush then flush id else check id
ziv@2290 24 end