Database Access and Local File Access Measurement Report

xiaoxiao2021-03-06  59

Always think that database access is much slower than local files, but it is unclear. Finally, I can't help but have a comparison test. Test Environment: OS --- Windows 2000 Server DatabaseServer ---- SQLServer 2000 Program Language: CSHARP Test: Read Parameter Table from the Database / Read Configuration Parameters in XML and instantiate the object.

Test procedures are as follows: using System; using System.Globalization; using System.IO; using System.Xml.Serialization; using System.Xml; using System.Data; using System.Data.SqlClient; public class Demo {public static void Main ( ) {System.console.writeline ("===== Executexml () ================================= ==== "); system.console.writeline (executexml ()); system.console.writeline (executexml ()); system.console.writeline (executexml ()); system.console.writeLine (Executexml ()) ; System.Console.WriteLine (executeXML ()); System.Console.WriteLine (executeXML ()); System.Console.WriteLine (executeXML ()); System.Console.WriteLine (executeXML ()); System.Console.WriteLine (Executexml ()); system.console.writeline (executexml ()); system.console.writeline ("======================================================================================================================================= ================================ "); system.console.writeline (" ===== ExecuteSQL () == ============================================== "); System.Console.writeline (ExecuteSQL ()); System .Console.writeLine (ExecuteSQL ()); System.con Sole.writeLine (ExecuteSQL ()); System.Console.writeline (ExecuteSQL ()); System.Console.writeline (ExecuteSQL ()); System.Console.writeline (ExecuteSQL ());

System.Console.WriteLine (ExecuteSQL ()); System.Console.WriteLine (ExecuteSQL ()); System.Console.WriteLine (ExecuteSQL ()); System.Console.WriteLine (ExecuteSQL ()); System.Console.WriteLine ( "=================================================== ======= / n ");} static double executesql () {string _connstring =" server = data-server; user ID = sa; password = 1234; dataWord = Leaddb; min pool size = 4; Max Pool size = 4; packet size = 3072 "; SqlCommand cmd = new SqlCommand (); SqlConnection conn = new SqlConnection (_connString); double begin = CultureInfo.InvariantCulture.Calendar.GetMilliseconds (DateTime.Now); try {conn.Open () ; cmd.Connection = conn; cmd.CommandText = "SELECT [CategoryId], [Name] FROM [SYS_Category] WHERE [CategoryType] = 2"; cmd.CommandType = CommandType.Text; SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.CloseConnection ); While (rdr.read ()) {new entity (rdr.getinT32 (0), rdr.getstring (1));} rdr.close ();} catch {conn.close (); t hrow;} begin = CultureInfo.InvariantCulture.Calendar.GetMilliseconds (DateTime.Now) - begin; return (begin> = 0) begin:? begin 1000.0;} static double ExecuteXML () {double begin = CultureInfo.InvariantCulture.Calendar. GetMilliseConds (DateTime.Now); XmLDocument Xmldoc = new xmldocument (); xmldoc.load (@ "f: /leadbridge/xcerp/web/onload/sys_category_headship.xml");

Foreach (xmlnode node in xmldoc.selectnodes) {new entity (INT.PARS (Node.attributes ["Id"]. Value), Node.innertext);} begin = CultureInfo.invariantculture.calendar. GetMilliseConds (DateTime.Now) - Begin; Return (Begin> = 0)? Begin: Begin 1000.0;}} PUBLIC CLASS Entity {PUBLIC Entity (Int Age, String Name) {this._age = age; this._name = Name ,} Private int _age; private int agent {get {return _age;} set {_age = value}}} public string name {}} public string name {{return _name;}}}} : ===== Executexml () ==================================================================================================================================================================================================================================================== ============================================================================================================================================================================================================= ======== executeSQL () ====================================================================================================================================================================================================================================================== ============================================================================================================================================================================================================= ===== During multiple tests, it is basically the difference between the order (a quantity level) (the first execution difference), so it is recommended,

转载请注明原文地址:https://www.9cbs.com/read-117081.html

New Post(0)