Message Boards Message Boards

0
|
2369 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Fastest way to write a very long expression to a file.

Posted 3 years ago

Hello everyone,

I was wondering what is the fastest way to write out a very long expression to a file in a human readable format, lets say InputForm with ASCII encoding. A suitable benchmark could be

expression = Plus @@ Table[1/n x^n, {n, 1, 2000000}];

or something with more terms. Using AbsoluteTiming, I see similar performance between Write and WriteString. Moreover, it looks like most of the time is spend converting the expression into a string

AbsoluteTiming[exprStr = ToString[expression, InputForm];]

Is this indeed the performance bottleneck, and if so, is there a way how the step can be speeded up?

POSTED BY: Tom Steudtner
2 Replies
Posted 3 years ago

Hi Tom,

Can you elaborate on why it has to be human readable? Is someone actually going to read an expression with 2 million terms?

POSTED BY: Rohit Namjoshi
Posted 3 years ago

Hi Rohit,

that might indeed take a bit longer than a few seconds!

What I actually meant by this is that the final output should not be e.g. binary data, but the uncompressed expression. I am trying to generate a large amount of source code.

POSTED BY: Tom Steudtner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract