Questions tagged [line-profiler]

Use this tag for questions about the Python "line_profiler" package. If you have a question about performance, or how to optimize your code based on "line_profiler" results, please use the more generic "performance" or "optimization" tags instead.

line_profiler is an external package allowing to measure the execution time (both relative and absolute) spent in each line. This can be an important utility to find bottlenecks or hotspots in python functions.

66 questions
0
votes
0 answers

line_profiler could not tell pandas assign details

def test_lprun(): data = {'Name':['Tom', 'Brad', 'Kyle', 'Jerry'], 'Age':[20, 21, 19, 18], 'Height' : [6.1, 5.9, 6.0, 6.1] } df = pd.DataFrame(data) df=df.assign(A=123, B=lambda x:x.Age+x.Height, …
Jack
  • 1,724
  • 4
  • 18
  • 33
0
votes
0 answers

Very weird performance behavior with pandas isin combined with boolean indexing with line_profiler

As seen here i am doing a isin() call which takes only 11126 to complete. Then i do a boolean indexing on that isin() but suddenly the time needed to complete that task is ~18x higher at 187088. 2 11126.0 5563.0 0.5 randomness =…
zacko
  • 179
  • 2
  • 9
0
votes
0 answers

Cyhton combined with line_profiler results in AttributeError: 'builtin_function_or_method' object has no attribute '__code__'

I'm trying to profile my Cython code using the line_profile package (The code runs but I want to know if I can optimize it..) but when I try to profile it I get an AttributeError: 'builtin_function_or_method' object has no attribute…
axel_ande
  • 359
  • 1
  • 4
  • 20
0
votes
1 answer

How to clear/reset results of the Python line profiler?

I'm trying to start and stop the line profiling of a Python function multiple times during runtime. Therefore I'd like to reset the already collected stats when starting a new profiling. Is there a way to do that? In lack of an obvious solution I…
Falko
  • 17,076
  • 13
  • 60
  • 105
0
votes
1 answer

Importing line_profiler on my m1 max leads to segmentation fault

As I said in the title importing line_profiler leads to segmentation fault. I am running python 3.9.7/conda-forge on a macbook pro m1 max. Does anyone have any suggestions how I can resolve this? % python Python 3.9.7 | packaged by conda-forge |…
Lukas S
  • 3,212
  • 2
  • 13
  • 25
0
votes
0 answers

Why does Python subprocess module run so slowly when pyTorch is using GPU?

I have been trying to use the python subprocess module while training a neural network in pytorch, but I noticed that subprocess runs many times slower if I have a network initialized on a gpu. Here is an example script I used, with a very simple…
0
votes
1 answer

Python kernprof line profiler wrong results

I have two functions which i profile. If i run kernprof, it says that my first function runs in 75 seconds but the second which is python-cythonized in 15. I already tried to use the time module in python and measure it by myself i see that it's…
supersick
  • 261
  • 2
  • 14
0
votes
1 answer

line profiler vs pytest --durations

I have two programs in python which do the same thing, in line profiler one program for certain test is faster than another but in pytest --durations(for this certain test) is viceversa. Can somebody explain that behaviour.I need know execution time…
Oakandrew
  • 1
  • 1
  • 3
0
votes
1 answer

Using line_profiler for an entire script without a main() function

I've just built a Raspberry Pi as a basic speed camera and want to make some tweaks to existing code. I've programmed before in various languages on and off for lots of projects, but not as a dedicated job. The code that I'm using is this (it's…
0
votes
0 answers

Python3.7 line_profiler ModuleNotFoundError

"ModuleNotFoundError: No module named 'my_toolkit'" I can run the script successfully.And I already add module my_toolkit into my sys path.However the kernprof.py cant recognize my toolkit.By the way,I can run memory_profile successfully. The…
Ramsey
  • 103
  • 7
0
votes
1 answer

How do I fix an unusual SyntaxError in the python executable itself when running line_profiler?

Here's a strange one. First of all: This is NOT a problem with the encoding of a python script file that I have written myself or am importing (see e.g. Working with UTF-8 encoding in Python source and the many duplicates thereof). I am running the…
jtlz2
  • 7,700
  • 9
  • 64
  • 114
0
votes
1 answer

How to install tortoise hg Mercurial on Windows, virtual environment

I am trying to install Django's debug_toolbar line profiler. As per the docs, I need to install Mercurial. I have installed Mercurial on my Windows machine and it looks OK when I type hg in the command prompt outside of my project's virtual…
EarlyCoder
  • 1,213
  • 2
  • 18
  • 42
0
votes
0 answers

UnicodeEncodeError when using line_profiler

I am learning python and try to analyze the code performance by line. I installed line_profiler but it always showed the UnicodeEncodeError: 'charmap' codec can't encode characters in position 30-31: character maps to undefined I tried to run chcp…
0
votes
1 answer

Can't install "line_profiler" with pip in Qt Console

When I tried to install "line_profiler" in QTconsole using !pip install line_profiler But it failed as saying, "Failed building wheel for line-profiler". I do not know why this happened. Is there any way to successfully install "line_profiler" in…
0
votes
1 answer

Optimized method for mapping contents of a column in a 2D numpy array

I have a numpy 2D array containing integers between 0 to 100. For a particular column, I want to map the values in the following way: 0-4 mapped to 0 5-9 mapped to 5 10-14 mapped to 10, and so on. This is my code: import numpy as np @profile def…
Bidisha Das
  • 177
  • 2
  • 11