| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  | USING: calendar math fry kernel assocs math.ranges bson.reader io.streams.byte-array | 
					
						
							|  |  |  | sequences formatting combinators namespaces io tools.time prettyprint io.encodings.binary | 
					
						
							| 
									
										
										
										
											2009-05-15 00:23:06 -04:00
										 |  |  | accessors words mongodb.driver strings math.parser bson.writer ;
 | 
					
						
							|  |  |  | FROM: mongodb.driver => find ;
 | 
					
						
							| 
									
										
										
										
											2009-06-05 08:31:40 -04:00
										 |  |  | FROM: memory => gc ;
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | IN: mongodb.benchmark | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 08:24:38 -05:00
										 |  |  | SYMBOL: collection | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : get* ( symbol default -- value )
 | 
					
						
							|  |  |  |     [ get ] dip or ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 08:52:28 -05:00
										 |  |  | : ensure-number ( v -- n )
 | 
					
						
							|  |  |  |     dup string? [ string>number ] when ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | : trial-size ( -- size )
 | 
					
						
							| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  |     "per-trial" 5000 get* ensure-number ; inline flushable
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : batch-size ( -- size )
 | 
					
						
							| 
									
										
										
										
											2009-03-07 08:52:28 -05:00
										 |  |  |     "batch-size" 100 get* ensure-number ; inline flushable
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | TUPLE: result doc collection index batch lasterror ;
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : <result> ( -- ) result new result set ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 08:52:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 08:06:53 -05:00
										 |  |  | CONSTANT: CHECK-KEY f  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | CONSTANT: DOC-SMALL H{ } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CONSTANT: DOC-MEDIUM H{ { "integer" 5 } | 
					
						
							|  |  |  |                         { "number" 5.05 } | 
					
						
							|  |  |  |                         { "boolean" f } | 
					
						
							|  |  |  |                         { "array" | 
					
						
							|  |  |  |                           { "test" "benchmark" } } } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CONSTANT: DOC-LARGE H{ { "base_url" "http://www.example.com/test-me" } | 
					
						
							|  |  |  |                        { "total_word_count" 6743 } | 
					
						
							|  |  |  |                        { "access_time" f }  | 
					
						
							|  |  |  |                        { "meta_tags" H{ { "description" "i am a long description string" } | 
					
						
							|  |  |  |                                         { "author" "Holly Man" } | 
					
						
							|  |  |  |                                         { "dynamically_created_meta_tag" "who know\n what" } } } | 
					
						
							|  |  |  |                        { "page_structure" H{ { "counted_tags" 3450 } | 
					
						
							|  |  |  |                                              { "no_of_js_attached" 10 } | 
					
						
							|  |  |  |                                              { "no_of_images" 6 } } } | 
					
						
							|  |  |  |                        { "harvested_words" { "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" | 
					
						
							|  |  |  |                                              "10gen" "web" "open" "source" "application" "paas"  | 
					
						
							|  |  |  |                                              "platform-as-a-service" "technology" "helps"  | 
					
						
							|  |  |  |                                              "developers" "focus" "building" "mongodb" "mongo" } } } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | : set-doc ( name -- )
 | 
					
						
							|  |  |  |     [ result ] dip '[ _ >>doc ] change ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  | : small-doc ( -- quot )
 | 
					
						
							|  |  |  |     "small" set-doc [ ] ; inline
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  | : medium-doc ( -- quot )
 | 
					
						
							|  |  |  |     "medium" set-doc [ ] ; inline
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  | : large-doc ( -- quot )
 | 
					
						
							|  |  |  |     "large" set-doc [ ] ; inline
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | : small-doc-prepare ( -- quot: ( i -- doc ) )
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     small-doc drop
 | 
					
						
							|  |  |  |     '[ "x" DOC-SMALL clone [ set-at ] keep ] ;  | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : medium-doc-prepare ( -- quot: ( i -- doc ) )
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     medium-doc drop
 | 
					
						
							|  |  |  |     '[ "x" DOC-MEDIUM clone [ set-at ] keep ] ;  | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : large-doc-prepare ( -- quot: ( i -- doc ) )
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     large-doc drop
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  |     [ "x" DOC-LARGE clone [ set-at ] keep  | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  |        [ now "access-time" ] dip
 | 
					
						
							|  |  |  |        [ set-at ] keep ] ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : (insert) ( quot: ( i -- doc ) collection -- )
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  |     [ trial-size ] 2dip
 | 
					
						
							| 
									
										
										
										
											2009-04-22 10:09:03 -04:00
										 |  |  |     '[ _ call( i -- doc ) [ _ ] dip
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |        result get lasterror>> [ save ] [ save-unsafe ] if ] each-integer ;  | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-22 10:09:03 -04:00
										 |  |  | : (prepare-batch) ( i b quot: ( i -- doc ) -- batch-seq )
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  |     [ [ * ] keep 1 range boa ] dip
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     '[ _ call( i -- doc ) ] map ;  | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : (insert-batch) ( quot: ( i -- doc ) collection -- )
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  |     [ trial-size batch-size [ / ] keep ] 2dip
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  |     '[ _ _ (prepare-batch) [ _ ] dip
 | 
					
						
							|  |  |  |        result get lasterror>> [ save ] [ save-unsafe ] if
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     ] each-integer ;  | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | : bchar ( boolean -- char )
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     [ "t" ] [ "f" ] if ; inline  | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : collection-name ( -- collection )
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  |     collection "benchmark" get* | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  |     result get doc>> | 
					
						
							|  |  |  |     result get index>> bchar | 
					
						
							|  |  |  |     "%s-%s-%s" sprintf | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     [ [ result get ] dip >>collection drop ] keep ;  | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  |      | 
					
						
							|  |  |  | : prepare-collection ( -- collection )
 | 
					
						
							|  |  |  |     collection-name | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  |     [ "_x_idx" drop-index ] keep
 | 
					
						
							|  |  |  |     [ drop-collection ] keep
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     [ create-collection ] keep ;  | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : prepare-index ( collection -- )
 | 
					
						
							| 
									
										
										
										
											2009-07-05 07:28:41 -04:00
										 |  |  |     "_x_idx" [ "x" asc ] key-spec <index-spec> t >>unique? ensure-index ;  | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : insert ( doc-quot: ( i -- doc ) -- quot: ( -- ) )
 | 
					
						
							| 
									
										
										
										
											2009-03-25 13:22:28 -04:00
										 |  |  |     prepare-collection | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  |     result get index>> [ [ prepare-index ] keep ] when
 | 
					
						
							|  |  |  |     result get batch>> | 
					
						
							|  |  |  |     [ '[ _ _ (insert-batch) ] ] [ '[ _ _ (insert) ] ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  | : serialize ( doc-quot: ( i -- doc ) -- quot: ( -- ) )
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     '[ trial-size [ _ call( i -- doc ) assoc>bv drop ] each-integer ] ;  | 
					
						
							| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : deserialize ( doc-quot: ( i -- doc ) -- quot: ( -- ) )
 | 
					
						
							| 
									
										
										
										
											2009-04-22 10:09:03 -04:00
										 |  |  |     [ 0 ] dip call( i -- doc ) assoc>bv | 
					
						
							| 
									
										
										
										
											2009-06-05 08:31:40 -04:00
										 |  |  |     '[ trial-size [  _ binary [ H{ } stream>assoc drop ] with-byte-reader ] times ] ;  | 
					
						
							| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | : check-for-key ( assoc key -- )
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     CHECK-KEY [ swap key? [ "ups... where's the key" throw ] unless ] [ 2drop ] if ;  | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-26 07:00:08 -04:00
										 |  |  | : (check-find-result) ( result -- )
 | 
					
						
							|  |  |  |     "x" check-for-key ; inline
 | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  | : (find) ( cursor -- )
 | 
					
						
							|  |  |  |     [ find [ (check-find-result) ] each (find) ] when* ; inline recursive
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  | : find-one ( quot -- quot: ( -- ) )
 | 
					
						
							|  |  |  |     drop
 | 
					
						
							| 
									
										
										
										
											2009-03-26 07:00:08 -04:00
										 |  |  |     [ trial-size | 
					
						
							|  |  |  |       collection-name | 
					
						
							|  |  |  |       trial-size 2 / "x" H{ } clone [ set-at ] keep
 | 
					
						
							|  |  |  |       '[ _ _ <query> 1 limit (find) ] times ] ;
 | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  | : find-all ( quot -- quot: ( -- ) )
 | 
					
						
							|  |  |  |     drop
 | 
					
						
							|  |  |  |     collection-name | 
					
						
							|  |  |  |     H{ } clone
 | 
					
						
							|  |  |  |     '[ _ _ <query> (find) ] ;
 | 
					
						
							| 
									
										
										
										
											2009-03-26 07:00:08 -04:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  | : find-range ( quot -- quot: ( -- ) )
 | 
					
						
							|  |  |  |     drop
 | 
					
						
							| 
									
										
										
										
											2009-03-26 07:00:08 -04:00
										 |  |  |     [ trial-size batch-size /i
 | 
					
						
							|  |  |  |        collection-name | 
					
						
							|  |  |  |        trial-size 2 / "$gt" H{ } clone [ set-at ] keep
 | 
					
						
							|  |  |  |        [ trial-size 2 / batch-size + "$lt" ] dip [ set-at ] keep
 | 
					
						
							|  |  |  |        "x" H{ } clone [ set-at ] keep
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |        '[ _ _ <query> (find) ] times ] ;
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | : batch ( -- )
 | 
					
						
							|  |  |  |     result [ t >>batch ] change ; inline
 | 
					
						
							|  |  |  |     | 
					
						
							|  |  |  | : index ( -- )
 | 
					
						
							|  |  |  |     result [ t >>index ] change ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : errcheck ( -- )
 | 
					
						
							|  |  |  |     result [ t >>lasterror ] change ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : print-result ( time -- )
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  |     [ result get [ collection>> ] keep
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  |       [ batch>> bchar ] keep
 | 
					
						
							|  |  |  |       [ index>> bchar ] keep
 | 
					
						
							|  |  |  |       lasterror>> bchar | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  |       trial-size ] dip
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  |     1000000 / /i
 | 
					
						
							| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  |     "%-18s: {batch:%s,index:%s;errchk:%s} %10s docs/s" | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     sprintf print flush ;  | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : print-separator ( -- )
 | 
					
						
							| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  |     "----------------------------------------------------------------" print flush ; inline
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : print-separator-bold ( -- )
 | 
					
						
							| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  |     "================================================================" print flush ; inline
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : print-header ( -- )
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  |     trial-size | 
					
						
							|  |  |  |     batch-size | 
					
						
							|  |  |  |     "MongoDB Factor Driver Benchmark\n%d ops per Trial, Batch-Size: %d" | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  |     sprintf print flush
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  |     print-separator-bold ;
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  | : with-result ( options quot -- )
 | 
					
						
							|  |  |  |     '[ <result> _ call( options -- time ) print-result ] with-scope ;  | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-22 10:09:03 -04:00
										 |  |  | : [bench-quot] ( feat-seq op-word -- quot: ( doc-word -- ) )
 | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  |     '[ _ swap _ | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |        '[ [ [ _ execute( -- quot ) ] dip
 | 
					
						
							| 
									
										
										
										
											2009-06-05 08:31:40 -04:00
										 |  |  |           [ execute( -- ) ] each _ execute( quot -- quot ) gc benchmark ] with-result ] each
 | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |        print-separator ] ;  | 
					
						
							| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : run-serialization-bench ( doc-word-seq feat-seq -- )
 | 
					
						
							|  |  |  |     "Serialization Tests" print
 | 
					
						
							|  |  |  |     print-separator-bold | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     \ serialize [bench-quot] '[ _ call( doc-word -- ) ] each ;  | 
					
						
							| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : run-deserialization-bench ( doc-word-seq feat-seq -- )
 | 
					
						
							|  |  |  |     "Deserialization Tests" print
 | 
					
						
							|  |  |  |     print-separator-bold | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     \ deserialize [bench-quot] '[ _ call( doc-word -- ) ] each ;  | 
					
						
							| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | : run-insert-bench ( doc-word-seq feat-seq -- )
 | 
					
						
							|  |  |  |     "Insert Tests" print
 | 
					
						
							| 
									
										
										
										
											2009-03-25 13:22:28 -04:00
										 |  |  |     print-separator-bold  | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     \ insert [bench-quot] '[ _ call( doc-word -- ) ] each ;  | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : run-find-one-bench ( doc-word-seq feat-seq -- )
 | 
					
						
							|  |  |  |     "Query Tests - Find-One" print
 | 
					
						
							|  |  |  |     print-separator-bold | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     \ find-one [bench-quot] '[ _ call( doc-word -- ) ] each ;  | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : run-find-all-bench ( doc-word-seq feat-seq -- )
 | 
					
						
							|  |  |  |     "Query Tests - Find-All" print
 | 
					
						
							|  |  |  |     print-separator-bold | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     \ find-all [bench-quot] '[ _ call( doc-word -- ) ] each ;  | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : run-find-range-bench ( doc-word-seq feat-seq -- )
 | 
					
						
							|  |  |  |     "Query Tests - Find-Range" print
 | 
					
						
							|  |  |  |     print-separator-bold | 
					
						
							| 
									
										
										
										
											2009-04-24 02:24:12 -04:00
										 |  |  |     \ find-range [bench-quot] '[ _ call( doc-word -- ) ] each ;  | 
					
						
							| 
									
										
										
										
											2009-03-07 07:54:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  |      | 
					
						
							|  |  |  | : run-benchmarks ( -- )
 | 
					
						
							| 
									
										
										
										
											2009-03-07 08:52:28 -05:00
										 |  |  |     "db" "db" get* "host" "127.0.0.1" get* "port" 27020 get* ensure-number <mdb> | 
					
						
							| 
									
										
										
										
											2009-03-27 11:33:49 -04:00
										 |  |  |     [ print-header | 
					
						
							|  |  |  |       ! serialization | 
					
						
							|  |  |  |       { small-doc-prepare medium-doc-prepare | 
					
						
							|  |  |  |         large-doc-prepare } | 
					
						
							|  |  |  |       { { } } run-serialization-bench | 
					
						
							|  |  |  |       ! deserialization | 
					
						
							|  |  |  |       { small-doc-prepare medium-doc-prepare | 
					
						
							|  |  |  |         large-doc-prepare } | 
					
						
							|  |  |  |       { { } } run-deserialization-bench | 
					
						
							| 
									
										
										
										
											2009-03-25 16:33:39 -04:00
										 |  |  |       ! insert | 
					
						
							|  |  |  |       { small-doc-prepare medium-doc-prepare | 
					
						
							|  |  |  |         large-doc-prepare } | 
					
						
							|  |  |  |       { { } { index } { errcheck } { index errcheck } | 
					
						
							|  |  |  |         { batch } { batch errcheck } { batch index errcheck } | 
					
						
							|  |  |  |       } run-insert-bench | 
					
						
							|  |  |  |       ! find-one | 
					
						
							|  |  |  |       { small-doc medium-doc large-doc } | 
					
						
							|  |  |  |       { { } { index } } run-find-one-bench | 
					
						
							|  |  |  |       ! find-all | 
					
						
							|  |  |  |       { small-doc medium-doc large-doc } | 
					
						
							|  |  |  |       { { } { index } } run-find-all-bench | 
					
						
							|  |  |  |       ! find-range | 
					
						
							|  |  |  |       { small-doc medium-doc large-doc } | 
					
						
							|  |  |  |       { { } { index } } run-find-range-bench         | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  |     ] with-db ;
 | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2009-03-07 08:24:38 -05:00
										 |  |  | MAIN: run-benchmarks | 
					
						
							| 
									
										
										
										
											2009-03-06 16:56:24 -05:00
										 |  |  | 
 |