andreinechaev / nvcc4jupyter

A plugin for Jupyter Notebook to run CUDA C/C++ code
MIT License
200 stars 87 forks source link

Convert TimeitResult object to human readable string #20

Closed cosminc98 closed 10 months ago

cosminc98 commented 11 months ago

Using the timeit option ("-t") throws an AttributeError in the helper.print_out function:

[<ipython-input-3-7685182fc153>](https://localhost:8080/#) in <cell line: 1>()
----> 1 get_ipython().run_cell_magic('cu', '-t', '#include <iostream>\nint\tmain()\n{\n\tstd::cout << "It works!\\n";\n\treturn 0;\n}\n')

5 frames
<decorator-gen-118> in cu(self, line, cell)

[/usr/local/lib/python3.10/dist-packages/common/helper.py](https://localhost:8080/#) in print_out(out)
     10 
     11 def print_out(out: str):
---> 12     for l in out.split('\n'):
     13         print(l)

AttributeError: 'TimeitResult' object has no attribute 'split'

This happens because this line in v1.py and this line in v2.py is a TimeitResult object which can be turned into a human readable string using its str dunder method.