Tag Info

Hot answers tagged

16

This variant should do what you want. g[x_Real] := h[Round[x,0.01]]; h[x_] := h[x] = Total[Table[x, {100000}]] Your Interpolation idea might give better accuracy though, if the function inquestion is sufficiently well behaved on your grid.


14

Please note that parts of the explanations and initialization code is shown together with the main function code, as a single large code block. I will appreciate any help on this matter - I am quite confused, perhaps overlooking something obvious here. Preamble While the question has been answered already, the delays with loading built-in data are a ...


13

Since Dan's already taken my initial solution, here's another approach that additionally allows you to specify the precision: f[x_, tol_] := f[Round[x, tol]] f[x_] := f[x] = Total[Table[x, {100000}]]


13

Initializing is not the same as downloading: I believe you are witnessing the data being unpacked for use.


12

Completely restarting the kernel will of course work. If we don't restart the kernel, then we need to clear all caches. The caches used for symbolic and some numeric calculations can be cleared using ClearSystemCache[]. The documentation page of this function says: ClearSystemCache can be useful in generating worst-case timing results independent of ...


9

You can introduce a second symbol as Daniel shows, but I am stingy with symbols and prefer this: g[x_?NumericQ] := g[{Round[x, 0.01]}]; m : g[{x_}] := m = Total[Table[x, {100000}]] You could use any head for this, even a string: g[x_?NumericQ] := g[ "rounded"[ Round[x, 0.01] ] ]; m : g["rounded"[x_]] := m = Total[Table[x, {100000}]] Delving into the ...


5

It's just a shot in the wild, but I would guess that you can switch off the caching with appropriate values to the corresponding system options: SystemOptions["CacheOptions"] (* ==> {"CacheOptions" -> {"CacheKeyMaxBytes" -> 1000000, "CacheResultMaxBytes" -> 1000000, "Constants" -> True, "Numeric" -> True, "Symbolic" -> True}} ...


4

When experimenting with Mathematica's caching, sometimes it can be clearer to look at memory usage rather than timing. When looking at individual functions, Mathematica is able to measure memory much more accurately than timing. The are a number of reasons why timing accuracy is off, such as the system clock resolution and fluctuations in the system use ...


3

Use MemoryConstrained MemoryConstrained[yourCode, memoryLimit, actionOnMemoryLimitOverflow]



Only top voted, non community-wiki answers of a minimum length are eligible