Changes between Version 15 and Version 16 of Python


Ignore:
Timestamp:
02/02/09 13:36:47 (15 years ago)
Author:
atzm
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Python

    v15 v16  
    43431 2 3 
    4444}}} 
     45 
     46== hidden read-ahead buffer == 
     47 * [http://docs.python.org/library/stdtypes.html#file.next Built-in Types -- Python v2.6.1 documentation (#file.next)] より 
     48{{{ 
     49In order to make a for loop the most efficient way of looping 
     50over the lines of a file (a very common operation), 
     51the next() method uses a hidden read-ahead buffer. 
     52}}} 
     53 
     54 * next() を見る 
     55   * コード 
     56{{{ 
     57#!python 
     58def printrss(): 
     59    pf = open('/proc/self/status') 
     60    for l in pf: 
     61        if l[:5] == 'VmRSS': 
     62            print l, 
     63    pf.close() 
     64 
     65def test(fname='/path/to/huge_file'): 
     66    f = open(fname) 
     67    c = 1 
     68    for i in f: 
     69        print '===== %d =====' % c 
     70        printrss() 
     71        c += 1 
     72    f.close() 
     73 
     74print 'test1' 
     75test() 
     76}}} 
     77   * 結果 
     78{{{ 
     79  :     :     : 
     80===== 1 ===== 
     81VmRSS:      2392 kB 
     82  :     :     : 
     83===== 11212 ===== 
     84VmRSS:      2408 kB 
     85}}} 
     86     * ちょっと (16KB) だけ増えてる 
     87 
     88 * readline() を見る 
     89   * コード 
     90{{{ 
     91#!python 
     92def printrss(): 
     93    pf = open('/proc/self/status') 
     94    for l in pf: 
     95        if l[:5] == 'VmRSS': 
     96            print l, 
     97    pf.close() 
     98 
     99def test(fname='/path/to/huge_file'): 
     100    f = open(fname) 
     101    c = 1 
     102    while True: 
     103        i = f.readline() 
     104        if not i: break 
     105        print '===== %d =====' % c 
     106        printrss() 
     107        c += 1 
     108    f.close() 
     109 
     110print 'test1' 
     111test() 
     112}}} 
     113   * 結果 
     114{{{ 
     115  :     :     : 
     116===== 1 ===== 
     117VmRSS:      2396 kB 
     118  :     :     : 
     119===== 11212 ===== 
     120VmRSS:      2396 kB 
     121}}} 
     122     * 増えてない 
    45123 
    46124== 日本語関連 ==