Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65405
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.045 |
| X-Spam-Evidence | '*H*': 0.91; '*S*': 0.00; 'dev': 0.07; 'calculating': 0.09; 'handful': 0.09; 'subject:using': 0.09; 'toss': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'sections': 0.14; 'block.': 0.16; 'dig': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'spit': 0.16; 'subject:Logging': 0.16; 'subject:PySerial': 0.16; 'time.time()': 0.16; 'true:': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'feb': 0.22; 'saying': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'helper': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'script': 0.25; 'suggested': 0.26; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'waste': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'are.': 0.31; 'though.': 0.31; 'quite': 0.32; '(including': 0.33; 'subject:from': 0.34; 'could': 0.34; 'etc': 0.35; 'hundreds': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'really': 0.36; 'collecting': 0.36; 'subject:data': 0.36; 'useful': 0.36; "i'll": 0.36; 'easily': 0.37; 'performance': 0.37; 'pm,': 0.38; 'track': 0.38; 'previous': 0.38; 'little': 0.38; 'short': 0.38; 'anything': 0.39; 'expensive': 0.39; 'itself': 0.39; 'enough': 0.39; 'even': 0.60; 'easy': 0.60; 'is.': 0.60; 'break': 0.61; 'length': 0.61; 'numbers': 0.61; "you'll": 0.62; 'soon': 0.63; 'thomas': 0.65; 'hours': 0.66; 'sample': 0.67; 'biggest': 0.67; 'improvements': 0.68; 'results': 0.69; 'wish': 0.70; 'serial': 0.72; '.....': 0.78; 'delay.': 0.84; 'pain': 0.84; 'simulation': 0.91; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=NWBpIDrald+eQ4YlhDhHS2kyhKFlYDN6hpnNrvCvH+c=; b=v90Hyu7rJm0x9Nn5FCF6RAH+QcrHKKAPXGxQrSG9wm8Q8ViDSp9bozE0b5VwDERKY3 3nqeIsfdJlfCNii424gA6DOnnMvmqFNhOSetItEpTQMeiBneC+P/vSWgDcYOK8O8aiNR ee03EGcgIyM9YGaJMaYU+2S7NkECxdhZkm42mb7ZV4q5M1aErLd3qWz+w6hNL2jd1wQD ftxi0UAAVkRsVckaNqijptoUtZPi2+e3qmqG65iFYk/bTT3yAOdI1icLNFe5vvT+AH3h 9YJbPT4Wvqy4Kdar/lnxCy+ov5TecEdIhcS62g+Dn8N1Qr9Aq5PfWj34sGm6i5YyLMt2 UdKA== |
| MIME-Version | 1.0 |
| X-Received | by 10.68.201.10 with SMTP id jw10mr41972032pbc.25.1391491091556; Mon, 03 Feb 2014 21:18:11 -0800 (PST) |
| In-Reply-To | <b21f1406-a294-4e70-b039-09024e7928e0@googlegroups.com> |
| References | <e3b195f8-5a17-4536-9926-2b2ab193719c@googlegroups.com> <mailman.6376.1391489248.18130.python-list@python.org> <b21f1406-a294-4e70-b039-09024e7928e0@googlegroups.com> |
| Date | Tue, 4 Feb 2014 16:18:11 +1100 |
| Subject | Re: Logging data from Arduino using PySerial |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6378.1391491099.18130.python-list@python.org> (permalink) |
| Lines | 55 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1391491099 news.xs4all.nl 2921 [2001:888:2000:d::a6]:52343 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:65405 |
Show key headers only | View raw
On Tue, Feb 4, 2014 at 3:57 PM, Thomas <t.tchorzewski@gmail.com> wrote:
> Wow...Thanks Chris! I really appreciate your suggestions (including the stylistic ones). I'll definitely be revising my code as soon as I find the time. As far as profiling goes, I've used timeit in the past but it's quite a pain going through any program block by block. I wish there were a program in which you could just toss in a script and it would spit out the bottlenecks in your code (with suggested performance improvements perhaps)...
>
Well, timeit is good for microbenchmarking. (How useful
microbenchmarking itself is, now, that's a separate question.) For
anything where you can "feel" the program's time by human, it's easy
enough to use the time.time() function.
Add a little helper like this (untested):
last_time = time.time()
def tt(desc):
global last_time
cur_time=time.time()
print("%s: %f"%(desc,cur_time-last_time))
last_time=cur_time
Then put this all through your code:
....
# Calculating the length of data to collect based on the
# sample time and simulation time (set by user)
max_length = sim_time/sample_time
tt("Init")
# Collecting the data from the serial port
while True:
data_log.append(connection.readline())
if len(data_log) > max_length - 1:
break
tt("Serial")
...
etc etc. Give it a short description saying what's just happened
(because it'll give the time since the previous timepoint), and then
just eyeball the results to see where the biggest numbers are. If you
do it right, you'll find a whole pile of sections with tiny numbers,
which you can easily ignore, and just a handful that even register.
Then you dig into those sections and see where the slowness is.
Be careful, though. You can easily waste hundreds of expensive dev
hours trying to track down an insignificant time delay. :)
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Logging data from Arduino using PySerial Thomas <t.tchorzewski@gmail.com> - 2014-02-03 20:07 -0800
Re: Logging data from Arduino using PySerial Chris Angelico <rosuav@gmail.com> - 2014-02-04 15:47 +1100
Re: Logging data from Arduino using PySerial Thomas <t.tchorzewski@gmail.com> - 2014-02-03 20:57 -0800
Re: Logging data from Arduino using PySerial Chris Angelico <rosuav@gmail.com> - 2014-02-04 16:18 +1100
Re: Logging data from Arduino using PySerial Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-04 08:56 -0500
Re: Logging data from Arduino using PySerial MRAB <python@mrabarnett.plus.com> - 2014-02-04 14:05 +0000
csiph-web