Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #48670
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Why is regex so slow? |
| Date | 2013-06-18 17:29 -0400 |
| References | <kpq2r9$gg6$1@panix2.panix.com> <mailman.3557.1371585950.3114.python-list@python.org> <kpqg0s$4q0$1@reader1.panix.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3559.1371590994.3114.python-list@python.org> (permalink) |
On 6/18/2013 4:30 PM, Grant Edwards wrote: > On 2013-06-18, Antoine Pitrou <solipsis@pitrou.net> wrote: >> Roy Smith <roy <at> panix.com> writes: >> >> You should read again on the O(...) notation. It's an asymptotic complexity, >> it tells you nothing about the exact function values at different data points. >> So you can have two O(n) routines, one of which always twice faster than the >> other. Or one that is a million times as fast. > And you can have two O(n) routines, one of which is twice as fast for > one value of n and the other is twice as fast for a different value of > n (and that's true for any value of 'twice': 2X 10X 100X). > > All the O() tells you is the general shape of the line. It doesn't > tell you where the line is or how steep the slope is (except in the > case of O(1), where you do know the slope is 0. It's perfectly > feasible that for the range of values of n that you care about in a > particular application, there's an O(n^2) algorithm that's way faster > than another O(log(n)) algorithm. In fact, Tim Peters put together two facts to create the current list.sort. 1. O(n*n) binary insert sort is faster than O(n*logn) merge sort, with both competently coded in C, for n up to about 64. Part of the reason is that binary insert sort is actually O(n*logn) (n binary searches) + O(n*n) (n insertions with a shift averaging n/2 items). The multiplier for the O(n*n) part is much smaller because on modern CPUs, the shift needed for the insertion is a single machine instruction. 2. O(n*logn) sorts have a lower assymtotic complexity because they divide the sequence roughly in half about logn times. In other words, they are 'fast' because they split a list into lots of little pieces. So Tim's aha moment was to think 'Lets stop splitting when pieces are less than or equal to 64, rather than splitting all the way down to 1 or 2". -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why is regex so slow? roy@panix.com (Roy Smith) - 2013-06-18 12:45 -0400
Re: Why is regex so slow? Skip Montanaro <skip@pobox.com> - 2013-06-18 12:01 -0500
Re: Why is regex so slow? Roy Smith <roy@panix.com> - 2013-06-18 13:08 -0400
Re: Why is regex so slow? Chris Angelico <rosuav@gmail.com> - 2013-06-19 03:20 +1000
Re: Why is regex so slow? Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-06-18 20:10 +0200
Re: Why is regex so slow? Roy Smith <roy@panix.com> - 2013-06-18 12:40 -0700
Re: Why is regex so slow? André Malo <ndparker@gmail.com> - 2013-06-18 21:59 +0200
Re: Why is regex so slow? André Malo <ndparker@gmail.com> - 2013-06-18 22:13 +0200
Re: Why is regex so slow? MRAB <python@mrabarnett.plus.com> - 2013-06-18 18:31 +0100
Re: Why is regex so slow? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-18 18:34 +0100
Re: Why is regex so slow? roy@panix.com (Roy Smith) - 2013-06-18 15:21 -0400
Re: Why is regex so slow? MRAB <python@mrabarnett.plus.com> - 2013-06-18 20:49 +0100
Re: Why is regex so slow? Rick Johnson <rantingrickjohnson@gmail.com> - 2013-06-18 12:21 -0700
Re: Why is regex so slow? Antoine Pitrou <solipsis@pitrou.net> - 2013-06-18 20:05 +0000
Re: Why is regex so slow? Roy Smith <roy@panix.com> - 2013-06-18 13:23 -0700
Re: Why is regex so slow? Duncan Booth <duncan.booth@invalid.invalid> - 2013-06-19 13:21 +0000
Re: Why is regex so slow? Roy Smith <roy@panix.com> - 2013-06-19 12:55 -0700
Re: Why is regex so slow? Grant Edwards <invalid@invalid.invalid> - 2013-06-18 20:30 +0000
Re: Why is regex so slow? Terry Reedy <tjreedy@udel.edu> - 2013-06-18 17:29 -0400
Re: Why is regex so slow? Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-06-19 10:29 +0200
Re: Why is regex so slow? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-19 01:51 +0000
Re: Why is regex so slow? Dave Angel <davea@davea.name> - 2013-06-18 22:11 -0400
Re: Why is regex so slow? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-19 03:16 +0000
csiph-web