Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I attempted to import a very short .txt file string using the Import command:

Import["C:\\TestFile.txt"] // AbsoluteTiming

Out: {0.020001, "Test"}

Why does this take 20 milliseconds? Export is about an order of magnitude faster for the same string:

Import["C:\\TestFile.txt","Test"] // AbsoluteTiming

Out: {0.002000, "C:\\test.txt"}

Are there any hidden options for Import like the following (concerning TIF files) from a previous question of mine Slow import of multigigabyte TIF image stacks?:


Quoting the user cormullion from my previous question: "For the OP's single frame, it's 0.015 for Import, but 0.000745 for ImageReadTIFF on Mac/M9. That might be worth having."

share|improve this question
Import comes with a lot of overhead. Try for example Import["testfile.txt", "Text"] // AbsoluteTiming versus just Import["testfile.txt"] and that removes just one test Import has to make. Then try ReadList["testfile.txt", "String"] // AbsoluteTiming which hasn't got the same sort of overhead. Also try Trace[Import["testfile.txt"]] to see exactly the internal functions used and the kind of tests performed. – Pickett Sep 7 '13 at 13:14

1 Answer 1

In the interest of reducing the number of questions that have been more or less thoroughly "answered in comments", I take the liberty to transform Pickett's insightful comment into an answer:

Import comes with a lot of overhead. Compare for example the following two snippets:


  Import["testfile.out", "Text"];

{0.329, Null}
{0.14, Null}

Simply providing Import with information on the format of the data removes a lot of content testing overhead!

You can compare the performance of Import with that of functions that don't need to carry out as much testing on their input, e.g. ReadList:

  ReadList["testfile.out", "String"];

(*Out: {0.027, Null} *)

Also an interesting idea is to look at Trace[Import["testfile.out"]] to see exactly the internal functions used and the kind of tests performed.

share|improve this answer
I think you've got your initial timings backwards ... – rcollyer Sep 29 at 19:26
@rcollyer I sure did! It's fixed now. Thank you for pointing that out! – MarcoB Sep 29 at 22:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.