root/tags/release2_2a1/sandbox/list_dir_test.py
| Revision 584, 2.9 kB (checked in by schwa, 2 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | #! /usr/bin/env python |
| 2 | # coding: iso-8859-1 |
| 3 | |
| 4 | # Copyright (C) 2006, Stefan Schwarzer |
| 5 | # All rights reserved. |
| 6 | # |
| 7 | # Redistribution and use in source and binary forms, with or without |
| 8 | # modification, are permitted provided that the following conditions are |
| 9 | # met: |
| 10 | # |
| 11 | # - Redistributions of source code must retain the above copyright |
| 12 | # notice, this list of conditions and the following disclaimer. |
| 13 | # |
| 14 | # - Redistributions in binary form must reproduce the above copyright |
| 15 | # notice, this list of conditions and the following disclaimer in the |
| 16 | # documentation and/or other materials provided with the distribution. |
| 17 | # |
| 18 | # - Neither the name of the above author nor the names of the |
| 19 | # contributors to the software may be used to endorse or promote |
| 20 | # products derived from this software without specific prior written |
| 21 | # permission. |
| 22 | # |
| 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 24 | # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 25 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 26 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR |
| 27 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 28 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 29 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 30 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 31 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 32 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 33 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 | |
| 35 | # $Id: $ |
| 36 | |
| 37 | # use experimental ftputil version |
| 38 | import sys |
| 39 | sys.path.insert(0, "/home/schwa/sd/python/ftputil.add_stat_caching") |
| 40 | |
| 41 | import ftputil |
| 42 | |
| 43 | |
| 44 | def main(): |
| 45 | test_dir = "pub/FreeBSD/doc" |
| 46 | ftp_host = ftputil.FTPHost("ftp.de.freebsd.org", 'anonymous', |
| 47 | "sschwarzer@sschwarzer.net") |
| 48 | def onerror(err): |
| 49 | print err |
| 50 | for top, dirs, nondirs in ftp_host.walk(test_dir, onerror=onerror): |
| 51 | print top |
| 52 | print " ", dirs |
| 53 | print " ", nondirs |
| 54 | |
| 55 | if top == "pub/FreeBSD/doc/fr_FR.ISO8859-1/books/ppp-primer": |
| 56 | break |
| 57 | print "Stat cache:" |
| 58 | print ftp_host.stat_cache |
| 59 | print len(ftp_host.stat_cache), "entries in cache" |
| 60 | ftp_host.close() |
| 61 | |
| 62 | |
| 63 | if __name__ == '__main__': |
| 64 | main() |
| 65 | |
| 66 | |
| 67 | # Time without caching: |
| 68 | # real 18m10.675s |
| 69 | # user 0m2.660s |
| 70 | # sys 0m0.796s |
| 71 | |
| 72 | # Time without cache, with current directory cache |
| 73 | # real 13m32.333s |
| 74 | # user 0m2.404s |
| 75 | # sys 0m0.672s |
| 76 | |
| 77 | # Second day |
| 78 | # real 14m36.256s |
| 79 | # user 0m2.080s |
| 80 | # sys 0m0.672s |
| 81 | |
| 82 | # real 13m55.254s |
| 83 | # user 0m2.868s |
| 84 | # sys 0m0.824s |
| 85 | |
| 86 | # Time with "infinite" cache, with current directory cache |
| 87 | # real 1m30.117s |
| 88 | # user 0m0.480s |
| 89 | # sys 0m0.112s |
| 90 | |
| 91 | # Dito, together with caching in listdir |
| 92 | # real 0m49.677s |
| 93 | # user 0m0.424s |
| 94 | # sys 0m0.100s |
| 95 |
Note: See TracBrowser for help on using the browser.
