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 mode: Read parameter tables from the database / read the number of records equivalent to the configuration parameters in XML and instantiate the object.
The test procedure is as follows:
Using system; 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 ("===== ExecuteleXml () ========================== ============== "); system.console.writeline (executexml ()); system.console.writeline (executexml ()); system.console.writeLine (Executexml ()); System.Tem .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 () ================================================================================================================================================== .WriteLine (ExecuteSQL ()); System.Console.WriteLine (ExecuteSQL ()); System.Console.WriteLine (ExecuteSQL ()); System.Console.WriteLine (ExecuteSQL ()); System.Console.WriteLine (ExecuteSQL () ); System.console.writeline (ExecuteSQL ()); System.co NSole.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;
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 (); throw;} begin = cultureInfo.invariantculture.calenfo.invariantculture.calendar.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/OnlineService/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; reburn (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 {_name = value;}}}}}
The result is as follows:
===== Executexml () =============================================================================================================================================================================================================== ============================================================================================================================================================================================================= ======= ExecuteSQL () ==================================================================================================================================================================================================================================================== ============================================================================================================================================================================================================= ==== During multiple tests, it is basically the difference between the above level (one quantity) (the first execution difference), so suggests that everyone is saved as a local parameter file in the form of a local parameter file in the form of a local parameter file The library reads efficient.