Speed
-
Hy I have a site on a host for ASP.NET. I have a file with 30000 records. I have a .mdf file with a table with 30000 records. Method 1 I read from file a record and diplay in a label. Label1.Text = File.ReadAllLines(Server.MapPath("~/fisier.txt"),Encoding.UTF8)[index]; Method 2 I read from .mdf file from my table the same record. Can tell me witch of the 2 method is faster? thx
-
Hy I have a site on a host for ASP.NET. I have a file with 30000 records. I have a .mdf file with a table with 30000 records. Method 1 I read from file a record and diplay in a label. Label1.Text = File.ReadAllLines(Server.MapPath("~/fisier.txt"),Encoding.UTF8)[index]; Method 2 I read from .mdf file from my table the same record. Can tell me witch of the 2 method is faster? thx
Probably the second, but both are a disaster, obviously. Well, readalllines returns a string[] as I recall, so it won't compile. ReadAllText is probably faster than the database solution, as it mindlessly reads and passes a single string. This does NOT mean that flat files are faster than databases.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Hy I have a site on a host for ASP.NET. I have a file with 30000 records. I have a .mdf file with a table with 30000 records. Method 1 I read from file a record and diplay in a label. Label1.Text = File.ReadAllLines(Server.MapPath("~/fisier.txt"),Encoding.UTF8)[index]; Method 2 I read from .mdf file from my table the same record. Can tell me witch of the 2 method is faster? thx
Method 2 is by far the most efficient. A specific record in the table can be accessed directly without having to read all of them. The ReadAllLines method will read the entire file and create an array that contains 30000 string objects. The memory used for this will be approximately double the file size, plus 120 kB for the array object itself. A less wasteful method to read the file would be to use a StreamReader to read line by line until you reach the line you want. That will not create a huge array in memory, and you don't have to read the entire file.
--- "Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things." -- Douglas Adams