rev: 3827f53bae88e48a594610914ba74b9512ead6dd tukan/testing/memslack.sc -rw-r--r-- 1.8 KiB View raw Log this file
3827f53bae88 — Leonard Ritter * more work on module system 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using import ..tukan.random

fn main ()
    global rnd : (Random)

    fn test-factor (factor)
        print "factor" factor
        let iters = 100000
        local total-wasted = 0:i64
        local total-allocs = 0:i32
        for k in (range iters)
            local wasted = 1
            local capacity = 1
            local count = 0
            local allocs = 0
            local copied = 0

            let q = 10000.0
            let a =
                log2 q
            let b =
                log2 (factor * q - 1.0)
            let total =
                a + (b - a) * ('random rnd f32)
            let total =
                i32 (2.0 ** total)
            for i in (range total)
                count += 1
                if (count > capacity)
                    wasted += capacity
                    capacity =
                        i32
                            (f32 capacity) * factor + 0.5
                    allocs += 1

            #print
                deref allocs
                "allocs"
            #print
                deref wasted
                "wasted,"
                deref capacity
                "capacity"
            #print "overhead"
                wasted + capacity - total
            total-wasted +=
                ((wasted + capacity) / total) as i64
            total-allocs += allocs
        print "wasted:"
            f32 (total-wasted / iters)
        #print "allocs:"
            total-allocs / iters
        print;

    test-factor 2.0
    test-factor 2.5
    test-factor e
    test-factor 2.9
    test-factor 3.0
    test-factor 4.0


#
    test-factor 1.5
    test-factor 2.0
    test-factor 3.0
    test-factor 4.0
    test-factor 8.0
    test-factor 16.0
    test-factor 32.0
    test-factor 64.0
    test-factor 128.0

define bleh
    static-compile
        static-typify main
        'O3

bleh;