c# - Most efficient way for reading IMDB movies list -


i reading imdb movies listing text file on harddrive (originally available imdb site @ ftp://ftp.fu-berlin.de/pub/misc/movies/database/movies.list.gz).

it takes around 5 minutes on machine (basic info: win7 x64bit, 16gb ram, 500 gb sata hardisk 7200 rpm) read file line line using code below.

i have 2 questions:

  1. is there way can optimize code improve read time?

  2. data access don't need sequential won't mind reading data top bottom / bottom top or order matter long read 1 line @ time. wondering there way read in multiple directions improve read time?

the application windows console application.

update: many responses correctly pointed out writing console takes substantial time. considering displaying of data on windows console desirable not mandatory.

//code block

string file = @"d:\movies.list"; filestream fs = new filestream(file, filemode.open, fileaccess.read, fileshare.none, 8, fileoptions.none); using (streamreader sr = new streamreader(fs)) { while (sr.peek() >= 0) { console.writeline(sr.readline()); } } 

i'm not whether more efficient or not, alternate method use file.readalllines:

var moviefile = file.readalllines(file); foreach (var movie in moviefile) console.writeline(movie); 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -