[pypy-svn] r53661 - in pypy/branch/io-improvements/pypy: rpython/module translator/goal

docgok at codespeak.net docgok at codespeak.net
Thu Apr 10 17:46:40 CEST 2008


Author: docgok
Date: Thu Apr 10 17:46:39 2008
New Revision: 53661

Added:
   pypy/branch/io-improvements/pypy/translator/goal/targetsimplewrite.py
Modified:
   pypy/branch/io-improvements/pypy/rpython/module/ll_os.py
Log:
Big os_write speedup.



Modified: pypy/branch/io-improvements/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/io-improvements/pypy/rpython/module/ll_os.py	(original)
+++ pypy/branch/io-improvements/pypy/rpython/module/ll_os.py	Thu Apr 10 17:46:39 2008
@@ -17,12 +17,13 @@
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.tool import rffi_platform as platform
 from pypy.rlib import rposix
+from pypy.rlib import rgc
 from pypy.tool.udir import udir
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.rpython.lltypesystem.rstr import mallocstr
 from pypy.rpython.annlowlevel import hlstr
 from pypy.rpython.lltypesystem.llmemory import raw_memcopy, sizeof,\
-     itemoffsetof, cast_ptr_to_adr, offsetof
+     itemoffsetof, cast_ptr_to_adr, cast_adr_to_ptr, offsetof
 from pypy.rpython.lltypesystem.rstr import STR
 
 posix = __import__(os.name)
@@ -512,17 +513,25 @@
 
         def os_write_llimpl(fd, data):
             count = len(data)
-            outbuf = lltype.malloc(rffi.CCHARP.TO, count, flavor='raw')
-            try:
-                for i in range(count):
-                    outbuf[i] = data[i]
+            if rgc.can_move(data):
+                outbuf = lltype.malloc(rffi.CCHARP.TO, count, flavor='raw')
+                try:
+                    for i in range(count):
+                        outbuf[i] = data[i]
+                    written = rffi.cast(lltype.Signed, os_write(
+                        rffi.cast(rffi.INT, fd),
+                        outbuf, rffi.cast(rffi.SIZE_T, count)))
+                    if written < 0:
+                        raise OSError(rposix.get_errno(), "os_write failed")
+                finally:
+                    lltype.free(outbuf, flavor='raw')
+            else:
+                outbuf = rffi.cast(rffi.VOIDP, data)
                 written = rffi.cast(lltype.Signed, os_write(
                     rffi.cast(rffi.INT, fd),
                     outbuf, rffi.cast(rffi.SIZE_T, count)))
                 if written < 0:
                     raise OSError(rposix.get_errno(), "os_write failed")
-            finally:
-                lltype.free(outbuf, flavor='raw')
             return written
 
         def os_write_oofakeimpl(fd, data):

Added: pypy/branch/io-improvements/pypy/translator/goal/targetsimplewrite.py
==============================================================================
--- (empty file)
+++ pypy/branch/io-improvements/pypy/translator/goal/targetsimplewrite.py	Thu Apr 10 17:46:39 2008
@@ -0,0 +1,30 @@
+import os
+
+def main(iterations=1):
+    dest = os.open('/dev/null', os.O_RDWR, 0777)
+    payload = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
+
+    for x in xrange(1024 * 1024 * iterations):
+        os.write(dest, payload)
+
+    os.close(dest)
+    
+def entry_point(argv):
+    if len(argv) > 1:
+        n = int(argv[1])
+    else:
+        n = 1
+    main(n)
+    return 0
+
+# _____ Define and setup target ___
+
+def target(*args):
+    return entry_point, None
+
+if __name__ == '__main__':
+    import sys
+    if len(sys.argv) >= 2:
+        main(iterations = int(sys.argv[1]))
+    else:
+        main()



More information about the Pypy-commit mailing list