Hot answers tagged


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.


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 ...


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 ...


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


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}]]


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 ...


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 ...


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}} *)...


You may make use of the built-in index caching for Entity objects; "WolframLanguageSymbol". lookupOptionFunction[optionName_String] := ToExpression /@ EntityValue[EntityList[ Entity["WolframLanguageSymbol", {EntityProperty["WolframLanguageSymbol", "OptionNames"] -> optionName}]], "Name"]] First run after creating ...


You can turn off caching in graphs by setting the system options: SetSystemOptions["GraphOptions" -> "CacheResults" -> False]


The behavior you are encountering is the time taken by Mathematica evaluate all the Symbols in the System context, including definitions (and Options) that are only loaded on first use. (For one of my own encounters with this delayed loading please see Why do I have to evaluate this twice?) In a fresh Kernel observe that GraphPlot has no Options: Quit[] (...


Use MemoryConstrained MemoryConstrained[yourCode, memoryLimit, actionOnMemoryLimitOverflow]

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