comparison caching-tests/bench.ur @ 2292:23eaec04e0f8

Ran a benchmark!
author Ziv Scully <ziv@mit.edu>
date Tue, 17 Nov 2015 04:08:12 -0500
parents ab6ca12debeb
children 8be54d7bd06e
comparison
equal deleted inserted replaced
2291:50ad02829abd 2292:23eaec04e0f8
1 table tab : {Id : int, Val : int} PRIMARY KEY Id 1 table tab : {Id : int, Val : int} PRIMARY KEY Id
2 2
3 fun check id = 3 fun check id =
4 res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]}); 4 res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]});
5 return <xml><body> 5 return <xml><body>
6 cache
6 {case res of 7 {case res of
7 None => <xml>?</xml> 8 None => <xml>?</xml>
8 | Some row => <xml>{[row.Tab.Val]}</xml>} 9 | Some row => <xml>{[row.Tab.Val]}</xml>}
9 </body></xml> 10 </body></xml>
10 11
11 fun flush id = 12 fun flush id =
12 dml (UPDATE tab SET Val = Val + 1 WHERE Id = {[id]}); 13 dml (UPDATE tab SET Val = Val + 1 WHERE Id = {[id]});
13 return <xml><body> 14 return <xml><body>
14 Changed {[id]}! 15 Changed {[id]}!
15 </body></xml> 16 </body></xml>
16
17 fun main x y =
18 r <- rand;
19 let
20 val id = r % x
21 val doFlush = (r / x) % y = 0
22 in
23 if doFlush then flush id else check id
24 end