~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/translator/js/examples/console/play1_snippets.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from pypy.conftest import gettestobjspace
 
2
 
 
3
class AppTest_pypy_c(object):
 
4
    def setup_class(cls):
 
5
        cls.space = gettestobjspace(**{"objspace.std.withtproxy": True,
 
6
            "usemodules":("_stackless",)})
 
7
        
 
8
    def test_snippet_1(self):
 
9
        from tputil import make_proxy
 
10
        history = []
 
11
        def recorder(operation):
 
12
            history.append(operation) 
 
13
            return operation.delegate()
 
14
 
 
15
        l = make_proxy(recorder, obj=[])
 
16
 
 
17
class AppTest_pypy_c_thunk(object):
 
18
    def setup_class(cls):
 
19
        cls.space = gettestobjspace(**{"objspace.name": 'thunk'})
 
20
 
 
21
    def test_snippet_1(self):
 
22
        from __pypy__ import thunk
 
23
        def f():
 
24
            print 'computing...'
 
25
            return 6*7
 
26
 
 
27
        x = thunk(f)
 
28
 
 
29
class AppTest_pypy_c_taint(object):
 
30
    def setup_class(cls):
 
31
        cls.space = gettestobjspace(**{'objspace.name': 'taint'})
 
32
 
 
33
    def test_snippet_1(self):
 
34
        from __pypy__ import taint
 
35
        x = taint(6)
 
36
 
 
37
class AppTest_pypy_cli(object):
 
38
    def setup_class(cls):
 
39
        cls.space = gettestobjspace(**{'usemodules': 'clr'})
 
40
 
 
41
    def test_snippet_1(self):
 
42
        import clr
 
43
        ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
 
44
        obj = ArrayList()
 
45
        obj.Add(1)
 
46
 
 
47
class AppTest_pyrolog_c(object):
 
48
    pass
 
49
 
 
50
class AppTest_python(object):
 
51
    pass
 
52
 
 
53
class AppTest_pypy_c_jit(object):
 
54
    def setup_class(cls):
 
55
        cls.space = gettestobjspace(**{'usemodules':('pypyjit',)})
 
56
 
 
57
    def test_snippet_1(self):
 
58
        import time
 
59
        
 
60
        def f1(n):
 
61
            "Arbitrary test function."
 
62
            i = 0
 
63
            x = 1
 
64
            while i<n:
 
65
                j = 0
 
66
                while j<=i:
 
67
                    j = j + 1
 
68
                    x = x + (i&j)
 
69
                i = i + 1
 
70
            return x
 
71
 
 
72
        def test_f1():
 
73
            res = f1(211)
 
74
            print "running..."
 
75
            N = 5
 
76
            start = time.time()
 
77
            for i in range(N):
 
78
                assert f1(211) == res
 
79
            end = time.time()
 
80
            print '%d iterations, time per iteration: %s' % (N, (end-start)/N)
 
81
 
 
82
        import pypyjit