home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code2 / v_bench / vbench.frm < prev    next >
Text File  |  1994-07-13  |  14KB  |  472 lines

  1. VERSION 2.00
  2. Begin Form Vbench 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "VBench"
  5.    ClientHeight    =   3228
  6.    ClientLeft      =   1584
  7.    ClientTop       =   660
  8.    ClientWidth     =   5172
  9.    Height          =   3648
  10.    Left            =   1536
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   3228
  13.    ScaleWidth      =   5172
  14.    Top             =   288
  15.    Width           =   5268
  16.    Begin TextBox Text1 
  17.       Height          =   372
  18.       Index           =   4
  19.       Left            =   2520
  20.       TabIndex        =   8
  21.       Text            =   "Text1"
  22.       Top             =   2160
  23.       Width           =   2412
  24.    End
  25.    Begin TextBox Text1 
  26.       Height          =   372
  27.       Index           =   3
  28.       Left            =   2520
  29.       TabIndex        =   7
  30.       Text            =   "Text1"
  31.       Top             =   1680
  32.       Width           =   2412
  33.    End
  34.    Begin TextBox Text1 
  35.       Height          =   372
  36.       Index           =   2
  37.       Left            =   2520
  38.       TabIndex        =   6
  39.       Text            =   "Text1"
  40.       Top             =   1200
  41.       Width           =   2412
  42.    End
  43.    Begin TextBox Text1 
  44.       Height          =   372
  45.       Index           =   1
  46.       Left            =   2520
  47.       TabIndex        =   5
  48.       Text            =   "Text1"
  49.       Top             =   720
  50.       Width           =   2412
  51.    End
  52.    Begin TextBox Text1 
  53.       Height          =   372
  54.       Index           =   0
  55.       Left            =   2520
  56.       TabIndex        =   4
  57.       Text            =   "Text1"
  58.       Top             =   240
  59.       Width           =   2412
  60.    End
  61.    Begin CommandButton Command1 
  62.       Caption         =   "E&xit"
  63.       Height          =   372
  64.       Index           =   3
  65.       Left            =   3840
  66.       TabIndex        =   3
  67.       Top             =   2760
  68.       Width           =   1092
  69.    End
  70.    Begin CommandButton Command1 
  71.       Caption         =   "&Populate"
  72.       Height          =   372
  73.       Index           =   2
  74.       Left            =   2640
  75.       TabIndex        =   2
  76.       Top             =   2760
  77.       Width           =   1092
  78.    End
  79.    Begin CommandButton Command1 
  80.       Caption         =   "&Select"
  81.       Height          =   372
  82.       Index           =   1
  83.       Left            =   1440
  84.       TabIndex        =   1
  85.       Top             =   2760
  86.       Width           =   1092
  87.    End
  88.    Begin CommandButton Command1 
  89.       Caption         =   "&Update"
  90.       Height          =   372
  91.       Index           =   0
  92.       Left            =   240
  93.       TabIndex        =   0
  94.       Top             =   2760
  95.       Width           =   1092
  96.    End
  97.    Begin Label Label1 
  98.       BackColor       =   &H00C0C0C0&
  99.       Caption         =   "Parameter QueryDef"
  100.       ForeColor       =   &H00FF0000&
  101.       Height          =   252
  102.       Index           =   4
  103.       Left            =   240
  104.       TabIndex        =   13
  105.       Top             =   2160
  106.       Width           =   2412
  107.    End
  108.    Begin Label Label1 
  109.       BackColor       =   &H00C0C0C0&
  110.       Caption         =   "Static QueryDef"
  111.       ForeColor       =   &H00FF0000&
  112.       Height          =   252
  113.       Index           =   3
  114.       Left            =   240
  115.       TabIndex        =   12
  116.       Top             =   1680
  117.       Width           =   2412
  118.    End
  119.    Begin Label Label1 
  120.       BackColor       =   &H00C0C0C0&
  121.       Caption         =   "Inline VB SQL"
  122.       ForeColor       =   &H00FF0000&
  123.       Height          =   252
  124.       Index           =   2
  125.       Left            =   240
  126.       TabIndex        =   11
  127.       Top             =   1200
  128.       Width           =   2412
  129.    End
  130.    Begin Label Label1 
  131.       BackColor       =   &H00C0C0C0&
  132.       Caption         =   "Dynaset FindFirst"
  133.       ForeColor       =   &H00FF0000&
  134.       Height          =   252
  135.       Index           =   1
  136.       Left            =   240
  137.       TabIndex        =   10
  138.       Top             =   720
  139.       Width           =   2412
  140.    End
  141.    Begin Label Label1 
  142.       BackColor       =   &H00C0C0C0&
  143.       Caption         =   "ISAM Table Seek"
  144.       ForeColor       =   &H00FF0000&
  145.       Height          =   252
  146.       Index           =   0
  147.       Left            =   240
  148.       TabIndex        =   9
  149.       Top             =   240
  150.       Width           =   2412
  151.    End
  152. End
  153. 'Declarations
  154.  
  155. Option Explicit
  156. Dim db As database
  157. Dim tbl As Table
  158. Dim dyna As dynaset
  159. Dim qd As querydef
  160. Dim foo As Integer
  161. Declare Function GetTickCount Lib "User" () As Long
  162.  
  163.  
  164. Sub CloseDb ()
  165. On Error Resume Next
  166.     dyna.Close
  167.     tbl.Close
  168.     qd.Close
  169.     db.Close
  170.     DoEvents
  171. End Sub
  172.  
  173. Sub Command1_Click (Index As Integer)
  174. Dim TimeCount As Long, TimeStart As Long
  175. Dim foobar As Integer, foo As Integer
  176. ReDim cost(5) As Double
  177.  
  178. TimeCount = 0
  179. 'Set the hourglass
  180. Screen.MousePointer = 11
  181.  
  182. Select Case Index
  183.  
  184. 'Update Operations ======================================
  185. 'The objective here is to examine 1000 out of 10,000 records,
  186. 'and modify those that match a given criteria - about 200 writes
  187. Case 0
  188.     Me.Caption = "VBench: Update Operation Benchmarks"
  189.     FileCopy "C:\vb\IoTest.Mdb", "C:\vb\IoTest.Bak"
  190.     'Seeks and indexed sequential updates ---------------
  191.     'Open the database logicals
  192.     OpenDb
  193.     'Start the clock
  194.     TimeStart = GetTickCount()
  195.     'Use transactions for speed
  196.     BeginTrans
  197.     'Jump to first ID using a fast seek
  198.     tbl.Seek ">=", 5000
  199.     'Continue searching till eof or break
  200.     Do Until tbl.EOF
  201.     'Test if reached top of range
  202.     If tbl!id < 6000 Then
  203.         'Test if record meets change criteria
  204.         If tbl!cost > 30 And tbl!cost < 40 Then
  205.         tbl.Edit
  206.         tbl!cost = tbl!cost * .9
  207.         tbl.Update
  208.         End If
  209.     Else
  210.         'Exit if past top of range
  211.         Exit Do
  212.     End If
  213.     'Get the next record
  214.     tbl.MoveNext
  215.     Loop
  216.     CommitTrans
  217.     'Stop the clock and report
  218.     TimeCount = GetTickCount() - TimeStart
  219.     Text1(0) = Format$(TimeCount / 1000, "##0.00")
  220.     CloseDb
  221.     'Dynaset FindFirst ---------------------------------------
  222.     'Start each iteration with same file
  223.     FileCopy "C:\vb\IoTest.bak", "C:\vb\IoTest.mdb"
  224.     'Open the data logicals
  225.     OpenDb
  226.     'Start The Clock
  227.     TimeStart = GetTickCount()
  228.     'Use transactions for speed
  229.     BeginTrans
  230.     'Jump to first record
  231.     dyna.FindFirst "Id >= 5000"
  232.     'Continue searching till eof or break
  233.     Do Until dyna.EOF
  234.     'Test if reached top of range
  235.     If dyna!id < 6000 Then
  236.         'Test if record meets change criteria
  237.         If dyna!cost > 30 And dyna!cost < 40 Then
  238.         dyna.Edit
  239.         dyna!cost = dyna!cost * .9
  240.         dyna.Update
  241.         End If
  242.     Else
  243.         'Exit loop if past top of range
  244.         Exit Do
  245.     End If
  246.     'Get the next record
  247.     dyna.MoveNext
  248.     Loop
  249.     CommitTrans
  250.     'Stop the clock and report
  251.     TimeCount = GetTickCount() - TimeStart
  252.     Text1(1) = Format$(TimeCount / 1000, "##0.00")
  253.     CloseDb
  254.     'Test SQL processing with inline VB code ----------
  255.     'Start each iteration with same file
  256.     FileCopy "C:\vb\IoTest.bak", "C:\vb\IoTest.mdb"
  257.     'Open the database logicals
  258.     OpenDb
  259.     'Start The Clock
  260.     TimeStart = GetTickCount()
  261.     'Execute the statement on databse DB
  262.     db.Execute "Update testtable Set Cost = Cost *.9 where cost > 30 and cost < 40 and id >= 5000 and id < 6000 and id/2 = id\2"
  263.     'Stop the clock and report
  264.     TimeCount = GetTickCount() - TimeStart
  265.     Text1(2) = Format$(TimeCount / 1000, "##0.00")
  266.     CloseDb
  267.     'Test SQL processing with Stored QueryDef -------
  268.     'Start each iteration with same file
  269.     FileCopy "C:\vb\IoTest.bak", "C:\vb\IoTest.mdb"
  270.     'Open the database logicals
  271.     OpenDb
  272.     'Store the procedure before starting the clock
  273.     Set qd = db.CreateQueryDef("TestQd", "Update testtable Set Cost = Cost *.9 where cost > 30 and Cost < 40 and id >= 5000 and id < 6000")
  274.     qd.Close
  275.     'Start The Clock
  276.     TimeStart = GetTickCount()
  277.     'Use Transactions for speed
  278.     BeginTrans
  279.     'Execute the querydef on database DB
  280.     db.Execute "TestQd"
  281.     CommitTrans
  282.     'Stop the clock and report
  283.     TimeCount = GetTickCount() - TimeStart
  284.     Text1(3) = Format$(TimeCount / 1000, "##0.00")
  285.     'Remove the querydef - normally we wouldn't do this
  286.     db.DeleteQueryDef "TestQd"
  287.     CloseDb
  288.     'ParameterQueryDef ------------------------------------
  289.     'Start each iteration with same file
  290.     FileCopy "C:\vb\IoTest.bak", "C:\vb\IoTest.mdb"
  291.     'Open the database logicals
  292.     OpenDb
  293.     'Store the procedure before starting the clock
  294.     Set qd = db.CreateQueryDef("TestQd", "Parameters IdSearch1 Long, IdSearch2 Long, CostSearch1 IEEEDouble, CostSearch2 IEEEDouble; Update testtable Set Cost = Cost *.9 where cost > CostSearch1 and cost < CostSearch2 and id >= IdSearch1 and id < IdSearch2")
  295.     qd.Close
  296.     'Start the clock
  297.     TimeStart = GetTickCount()
  298.     BeginTrans
  299.     'Open the querydef
  300.     Set qd = db.OpenQueryDef("TestQd")
  301.     'Set the paramter values
  302.     qd!IdSearch1 = 5000
  303.     qd!IdSearch2 = 6000
  304.     qd!CostSearch1 = 30
  305.     qd!CostSearch2 = 40
  306.     'Execute the querydef
  307.     qd.Execute
  308.     CommitTrans
  309.     'Stop the clock and report
  310.     TimeCount = GetTickCount() - TimeStart
  311.     Text1(4) = Format$(TimeCount / 1000, "##0.00")
  312.     'Remove the querydef - normally we wouldn't do this
  313.     qd.Close
  314.     db.DeleteQueryDef "TestQd"
  315.     CloseDb
  316.  
  317. 'Select Operations ======================================
  318. 'The objective of this benchmark is to read selected records From
  319. 'X to Y. For seeks and findfirst we need to get to X,then move
  320. 'through the records testing the criteria. For QueryDefs we need
  321. 'to select the desired records and then scan them all to achieve
  322. 'a similar result. Our criteria is all records with an even numbered
  323. 'ID between 5000 and 5100, for example 5000, 5002, 5004, etc.
  324. Case 1
  325.     Me.Caption = "VBench: Select Operation Benchmarks"
  326.     'Initialize and open the database logicals
  327.     OpenDb
  328.     'Table Seek -------------------------------------------------
  329.     'Start the clock
  330.     TimeStart = GetTickCount()
  331.     'Repeat the operation to get a meaningful time
  332.     For foo = 1 To 10
  333.     'Position to the first record with a seek
  334.     tbl.Seek "=", 5001
  335.     'Look at each record
  336.     For foobar = 1 To 98
  337.         If tbl!id / 2 = tbl!id \ 2 Then
  338.         'do something if it is even
  339.         End If
  340.         tbl.MoveNext
  341.     Next foobar
  342.     'Reset for next seek
  343.     tbl.Seek "=", 1
  344.     Next foo
  345.     'Stop the clock and report
  346.     TimeCount = GetTickCount() - TimeStart
  347.     Text1(0) = Format$(TimeCount / 1000, "##0.00")
  348.     'Dynaset FindFirst ---------------------------------------
  349.     dyna.MoveFirst
  350.     'Start The Clock
  351.     TimeStart = GetTickCount()
  352.     'This operation is slow enough we don't have to repeat it
  353.     'Jump to first record
  354.     dyna.FindFirst "Id = 5000"
  355.     For foo = 1 To 99
  356.     If dyna!id / 2 = dyna!id \ 2 Then
  357.         'do something if it is even
  358.     End If
  359.     dyna.MoveNext
  360.     Next foo
  361.     'We're positioned and ready to process, so stop benchmark
  362.     'Stop the clock and report
  363.     TimeCount = GetTickCount() - TimeStart
  364.     Text1(1) = Format$(TimeCount / 100, "##0.00")
  365.     'Inline VB SQL Code ------------------------------------
  366.     'Start The Clock
  367.     TimeStart = GetTickCount()
  368.     For foo = 1 To 10
  369.     'Execute the statement on databse DB
  370.     dyna.Close
  371.     Set dyna = db.CreateDynaset("Select * From Testtable where Id >= 5000 and Id < 5100 and Id \ 2 = Id / 2")
  372.     Do Until dyna.EOF
  373.         dyna.MoveNext
  374.     Loop
  375.     Next foo
  376.     'Stop the clock and report
  377.     TimeCount = GetTickCount() - TimeStart
  378.     Text1(2) = Format$(TimeCount / 1000, "##0.00")
  379.     'Static QueryDef ------------------------------------------
  380.     'Store the procedure before starting the clock
  381.     Set qd = db.CreateQueryDef("TestQd", "Select * From TestTable where Id >= 5000 and Id < 5100 and Id \ 2 = Id / 2")
  382.     qd.Close
  383.     'Start The Clock
  384.     TimeStart = GetTickCount()
  385.     For foo = 1 To 10
  386.     'Execute the querydef on database DB
  387.     dyna.Close
  388.     Set dyna = db.CreateDynaset("TestQd")
  389.     Do Until dyna.EOF
  390.         dyna.MoveNext
  391.     Loop
  392.     Next foo
  393.     'Stop the clock and report
  394.     TimeCount = GetTickCount() - TimeStart
  395.     Text1(3) = Format$(TimeCount / 1000, "##0.00")
  396.     'Remove the QueryDef
  397.     db.DeleteQueryDef ("TestQd")
  398.     'Parameter QueryDef ------------------------------------
  399.     'Init the db
  400.     CloseDb
  401.     OpenDb
  402.     'Store the procedure before starting the clock
  403.     Set qd = db.CreateQueryDef("TestQd", "Parameters IDSearch1 Long, IDSearch2 Long; Select * From Testtable where id >= IDSearch1 and Id < IdSearch2 and Id \ 2 = Id / 2")
  404.     qd.Close
  405.     'Start the clock
  406.     TimeStart = GetTickCount()
  407.     For foo = 1 To 10
  408.     'Open the querydef
  409.     Set qd = db.OpenQueryDef("TestQd")
  410.     'Set the paramter values
  411.     qd!IdSearch1 = 5000
  412.     qd!IdSearch2 = 5100
  413.     'Build the dynaset from the querydef
  414.     dyna.Close
  415.     'Note the required alternate syntax!
  416.     Set dyna = qd.CreateDynaset()
  417.     Do Until dyna.EOF
  418.         dyna.MoveNext
  419.     Loop
  420.     'Close the querydef
  421.     qd.Close
  422.     Next foo
  423.     'Stop the clock and report
  424.     TimeCount = GetTickCount() - TimeStart
  425.     Text1(4) = Format$(TimeCount / 1000, "##0.00")
  426.     'Remove the QueryDef
  427.     db.DeleteQueryDef ("TestQd")
  428.     CloseDb
  429.     
  430. 'Populate the DB Test Set ============================================
  431. Case 2
  432.     Me.Caption = "VBench: Populate Database"
  433.     'Initialize costs so we'll have a nice variety
  434.     cost(1) = 19.95
  435.     cost(2) = 29.95
  436.     cost(3) = 39.95
  437.     cost(4) = 49.95
  438.     cost(5) = 9.95
  439.     'Use transactions for speed
  440.     BeginTrans
  441.     OpenDb
  442.     db.Execute "Delete * from TestTable"
  443.     For foo = 1 To 10000
  444.     foobar = foobar + 1
  445.     If foobar > 5 Then foobar = 1
  446.     tbl.AddNew
  447.     tbl!cost = cost(foobar)
  448.     tbl!id = foo
  449.     tbl.Update
  450.     Next foo
  451.     CommitTrans
  452.     CloseDb
  453. 'Exit the program ====================================================
  454. Case 3
  455.     Screen.MousePointer = 0
  456.     End
  457. End Select
  458.  
  459. Screen.MousePointer = 0
  460.  
  461. End Sub
  462.  
  463. Sub OpenDb ()
  464. On Error GoTo 0
  465.     'Open the logicals
  466.     Set db = OpenDatabase("C:\vb\IoTest.mdb")
  467.     Set tbl = db.OpenTable("TestTable")
  468.     tbl.Index = "IdKey"
  469.     Set dyna = db.CreateDynaset("TestTable")
  470. End Sub
  471.  
  472.