0

I have written a program which would fetch file details and place them in the SQLite database. In this process i have observed two scenarios:

Scenario 1:

  1. Loop through each and every file and fill the file details(path) in to the database(sqlite3).
  2. While for each file encountered,keep a counter and print the same via std::cout. Time taken to execute this program:30mins

Scenario 2:

  1. Loop through each and every file and fill the file details(path) in to the database(sqlite3).

Time taken to execute this program:7mins

I am very unclear as of why just because of std::cout,the time taken is 5 times more than that of not printing it?

Any pointers on this scenario is highly appreciated.Thanks a lot.

Regards, Ravi

UmNyobe
  • 21,341
  • 8
  • 52
  • 85

2 Answers2

0

try to use std::ios_base::sync_with_stdio(false), by default std::cout sync with stdio

Mike Minaev
  • 1,542
  • 2
  • 19
  • 29
0

Printing to console is costly. Usually more time-consuming than writing to a file.

I bet your code could run in less than a minute. Make sure you surround some inserts in a transaction. You can also use multiple inserts in one statement, like explained in answers to this question.

Community
  • 1
  • 1
Dariusz
  • 19,750
  • 7
  • 65
  • 104
  • I have already been using transaction and auto vacuum options from sqlite3 db.I am only worried about why exactly the cout is taking more time(5 times).. – user3264565 Mar 10 '14 at 08:56