11
$\begingroup$

I found a strange phenomenon that Mathematica is getting slow when I repeatedly called an external program by using ReadList. For example, the following code will display a significant increase of CPU time for each 'ls' command (my platform is OS X):

data = Table[Timing[ReadList["!ls"]], {100000}][[All, 1]];
ListPlot[data]

enter image description here

This phenomenon seems ubiquitous for the other external programs. Can anyone suggest me how to avoid this speed down?

$\endgroup$
  • 1
    $\begingroup$ Is this actually a problem or just an annoyance? When you say other external programs do you include ones with more significant IO than a simple ls? Additionally does it do the same if you call ls through a shell script? Ie are you sure it's MMA and not just OSX? $\endgroup$ – Gordon Coale Jun 25 '15 at 6:00
  • 1
    $\begingroup$ Confirmed same issue on my MBA running Mavericks and MMA10.1. One point to note is my results for same code are 10 times faster i.e. 0.002 to 0.006 although the trend is very similar. This may just be due to directory contents, or maybe my SSD? $\endgroup$ – Gordon Coale Jun 25 '15 at 8:47
  • 1
    $\begingroup$ Might be a good idea to send a bug report to WRI and see what they have to say about it. $\endgroup$ – C. E. Jun 25 '15 at 11:37
  • 4
    $\begingroup$ I had to change the code to the following: data = Table[Timing[Do[ReadList["!dir", "String"], {250}]], {100}][[All, 1]]; ListPlot[data, PlotRange -> All]. However, with this I could not reproduce your observations on Windows. The timings appeared scattered in an essentially random way. $\endgroup$ – Oleksandr R. Jun 25 '15 at 12:23
  • 1
    $\begingroup$ Perhaps some stream or channel is not being closed properly with this code under OS X? $\endgroup$ – Mr.Wizard Jun 25 '15 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.