Login Register






Fast I/O filter_list
Author
Message
Fast I/O #1
I'm having trouble with my I/O performance, I have this piece of code which reads a file of 2MB and then converts each text to it's Hash and then compares it with a given hash. Now It's talking way too much time.

I tried picking a word from the mid of the list but still it's taking a very very long time, I can't seem to find the problem or either my method sucks. I did some googling and people were suggesting to use Memory Mapped files but I'm not familiar with em.

Code:
Code:
int main() { //menu(); MD5 md5; char y[32]; //Load Dictionary File std::ifstream dict ("test.txt"); if(check_dict("test.txt")) { //Char Limit char test[25]; //Get the items from the file for(int i = 0; i < count_file("test.txt"); i++) { dict >> test; strncpy(y, test, sizeof(y)); if(md5.digestString(y) == "f0775b2755cb09221eb72ddf843a7d05") { std::cout << "Your cracked string is: " << test << std::endl; } else { std::cout << "Fail Hash...." << std::endl; } } } system("pause"); }


The point is I need to reduce the time taken, An idea which I have is:

Split the text file into two, Create 2 threads and give each half to the respective thread then do the work but this is just my assumption, Haven't tested it yet.
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG


RE: Fast I/O #2
Multi-threading sounds a good solution IMO...

Also, I would remove all outputs in the loop!

[note] Reason why I posted here is that I would like to follow this thread, and sadly I can't find another way to do so!

[note] Thanks to @Snipa now I know how to subscribe to a thread lol
[Image: wvBFmA5.png]


RE: Fast I/O #3
Have you tried using mmap() as it can be used for handling large files.
http://man7.org/linux/man-pages/man2/mmap.2.html

Please have a look here :- http://en.wikibooks.org/wiki/Optimizing_...put/Output

http://www.unix.org/version2/whatsnew/lfs20mar.html
[Image: OilyCostlyEwe.gif]


RE: Fast I/O #4
@Psycho_Coder Thanks man, People over Stackoverflow were too recommending to use mmap for handling large files, I'll give your links a go..

@Ligeti Well I'll surely be giving my idea a try also I agree with removing the output Smile

Thanks for the input guys
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG


RE: Fast I/O #5
Multi-threading won't really make this much faster just by itself. Without seeing what some of these other user-defined functions look like, it's hard to say...
Code:
count_file("test.txt")

I would take this out of the loop though. Along with the else condition because writing to the standard output stream takes time.

Also, MMAP is Linux specific for the most part, but for Windows, you'll want to use CreateFileMapping(), and UnmapViewOfFile().
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]


RE: Fast I/O #6
(03-14-2014, 01:40 AM)ArkPhaze Wrote: Multi-threading won't really make this much faster just by itself. Without seeing what some of these other user-defined functions look like, it's hard to say...
Code:
count_file("test.txt")

I would take this out of the loop though. Along with the else condition because writing to the standard output stream takes time.

Also, MMAP is Linux specific for the most part, but for Windows, you'll want to use CreateFileMapping(), and UnmapViewOfFile().

Sir you just saved my day! My program works awesome now, the speed got blazing after removing count_file() and providing the loop with a variable which stored the functions returned value.

Thank you very much!

Thread Closed and Marked solved!
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG