When I hit shift+enter at a document, I must wait for a long time. But AbsoluteTiming function indicates it just spent under 1 second. as follows.

enter image description here

I think it shows that only 0.24sec took to subtract two sub-matricies, but I have to wait the result almost 1 minute! How can I make this work fast?

  • 2
    $\begingroup$ Please do not post images of your work, especially when the images display at a size that make them unreadable. Please post your actual Mathematica code as text that can be copied and pasted in a Mathematica notebook. Without such, no one will be able to reproduce your problem, nor will they be able to experiment with possible repairs. Make sure to include data that can reproduce the problem. $\endgroup$ – m_goldberg Jul 31 '15 at 1:58
  • 3
    $\begingroup$ Most of what you're waiting on is the front end rendering the enormous matrix output. Try {timing,imgdd}=AbsoluteTiming[ ... ]; time That should go faster, and you'll separate your timing info from the image. $\endgroup$ – N.J.Evans Jul 31 '15 at 3:05
  • 1
    $\begingroup$ @m_goldberg OK. I will. Actually I tried, but I cannot copy the terminal text. I dragged the command lines but I cannot select them. It seems like there is another way to copy the whole text but I don’t know that yet. Anyway, I’m sorry for other’s inconvenience. $\endgroup$ – plhn Jul 31 '15 at 3:56
  • $\begingroup$ @N.J.Evans Thank you for your advice. I’m struggling with this problem, at this moment, I just suppress output with the ending semicolon, but it would be nicer if there is some options to output large matrix. For example, if a large matrix must be shown, it’s header part of some rows are shown only. etc. $\endgroup$ – plhn Jul 31 '15 at 4:00
  • 2
    $\begingroup$ @plhn It sounds like you are looking for Short or Shallow perhaps? You need to specify more exactly the kind of abridged output you wish to see. $\endgroup$ – Mr.Wizard Jul 31 '15 at 4:39

What takes a long time is formatting the output. Even though just a small blue box is shown, the output is in fact very large, and Mathematica probably tries to process it before deciding that it's just too big to show.

AbsoluteTiming only measures the time taken to compute something (by the kernel), not the time taken to format it (by the front end, and, partially, by the kernel using MakeBoxes)

So use a semicolon to suppress the output and it will be fast.

Apart from this, there's a mistake in how you use // AbsoluteTiming. Compare:

a = 1 // f
(* f[1] *)

(* f[1] *)

a = 1; // f
(* f[Null] *)

(* 1 *)

I assume you didn't want to record the result of AbsoluteTiming but the result of the subtraction. Adding the semicolon will fix this as well.

|improve this answer|||||

Your Answer

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

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