Skip to content

Allow %memit to return a result object and to be quiet #116

Merged
fabianp merged 3 commits intopythonprofilers:masterfrom
wasade:returnable_memit
Jun 29, 2016
Merged

Allow %memit to return a result object and to be quiet #116
fabianp merged 3 commits intopythonprofilers:masterfrom
wasade:returnable_memit

Conversation

@wasade
Copy link
Copy Markdown
Contributor

@wasade wasade commented Jun 27, 2016

An example of its use is below. The object and implementation were adapted from IPython's timeit returnable.

> %load_ext memory_profiler

> %memit -r 10 1+2
peak memory: 25.06 MiB, increment: 0.15 MiB

> result = %memit -o -r 10 1+2
peak memory: 24.10 MiB, increment: 0.01 MiB

> result
Out[4]: <MemitResult : peak memory: 24.10 MiB, increment: 0.01 MiB>

> result.mem_usage
Out[5]:
[24.0859375,
 24.09765625,
 24.09765625,
 24.09765625,
 24.09765625,
 24.09765625,
 24.09765625,
 24.09765625,
 24.09765625,
 24.09765625]

@wasade wasade changed the title ENH: allow memit magic to return a result object Allow %memit to return a result object and to be quiet Jun 27, 2016
Comment thread memory_profiler.py Outdated
if not quiet:
if mem_usage:
max_mem = max(mem_usage)
print('peak memory: %.02f MiB, increment: %.02f MiB' %
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to duplicate _repr_pretty_ of MemitResult.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close, but not exactly, as the logic of _repr_pretty_ writes to a RepresentationPrinter supplied by IPython. I've refactored though so a __str__ can be obtained from MemitResult and revised the if-statement in memit.

@fabianp
Copy link
Copy Markdown
Collaborator

fabianp commented Jun 28, 2016

Thanks for the patch. Could you take into account @superbobry's comments? Otherwise the code looks good to me.

@fabianp fabianp merged commit aa8b30c into pythonprofilers:master Jun 29, 2016
@fabianp
Copy link
Copy Markdown
Collaborator

fabianp commented Jun 29, 2016

Merged. Thanks @wasade for the patch and @superbobry for the comments

@wasade
Copy link
Copy Markdown
Contributor Author

wasade commented Jun 29, 2016

Great, thank you both!
On Jun 29, 2016 2:15 AM, "Fabian Pedregosa" notifications@github.com
wrote:

Merged. Thanks @wasade https://github.com/wasade for the patch and
@superbobry https://github.com/superbobry for the comments


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/fabianp/memory_profiler/pull/116#issuecomment-229302258,
or mute the thread
https://github.com/notifications/unsubscribe/AAc8sgSoDBOo6zAKWdRRq0owWrd4xZv8ks5qQjfJgaJpZM4I_nGB
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants