Nmap Security Scanner
*Intro
*Ref Guide
*Install Guide
*Download
*Changelog
*Book
*Docs
Security Lists
*Nmap Hackers
*Nmap Dev
*Bugtraq
*Full Disclosure
*Pen Test
*Basics
*More
Security Tools
*Pass crackers
*Sniffers
*Vuln Scanners
*Web scanners
*Wireless
*Exploitation
*Packet crafters
*More
Site News
Site Search:
Exploit World
Advertising
About/Contact
Credits
Sponsors:
edgeos

Dailydave: Re: A small fun Python puzzle

Re: A small fun Python puzzle

From: Daryl Tester <dt-dailydave_at_handcraftedcomputers.com.au>
Date: Tue, 01 Apr 2008 07:04:49 +1030

Dave Aitel wrote:

> This is part of our smb file putter. With small files it works great.
> With larger files, it uses 100% of the CPU and takes forever. Can anyone
> spot why? (Answer forthcoming, of course)

Depending on the value of "large", I suspect slicing and garbage
collection become expensive operations. Given -

import time
def test(l):
  data = ' ' * l
  t = time.time()
  while data != "":
    data = data[1024:]
  return time.time() - t

results in:

>>> for l in [100000, 1000000, 5000000, 10000000]:
... print '%10d %f' % (l, test(l))
...
    100000 0.006711
   1000000 0.764886
   5000000 28.554786
  10000000 111.738498

(wow - so not linear ...)

An iterative version appears a lot faster (which, admittedly,
probably rules out the slicing operation) -

def test2(l):
  data = ' ' * l
  i = 0
  t = time.time()
  while i < l:
    data2 = data[i:i+1024]
    i += 1024
  return time.time() - t

>>> for l in [100000, 1000000, 5000000, 10000000]:
... print '%10d %f' % (l, test2(l))
...
    100000 0.000320
   1000000 0.003319
   5000000 0.012145
  10000000 0.021329

-- 
Regards,
  Daryl Tester
"We are sexy, sexy Von Neumann machines."  -- http://www.xkcd.org/387/
_______________________________________________
Dailydave mailing list
Dailydave_at_lists.immunitysec.com
http://lists.immunitysec.com/mailman/listinfo/dailydave
Received on Apr 01 2008
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]