Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
332 additions
and 198 deletions.
- +0 −39 tests/jit/test_basic.py
- +74 −0 tests/jit/test_instance_vars.py
- +17 −15 tests/test_mapdict.py
- +214 −116 topaz/mapdict.py
- +27 −28 topaz/objects/objectobject.py
@@ -1,39 +1,41 @@ | ||
import pytest | ||
|
||
from topaz.mapdict import ClassNode | ||
|
||
from .base import BaseTopazTest | ||
from topaz import mapdict | ||
|
||
|
||
class FakeObject(object): | ||
storage = None | ||
|
||
def __init__(self, map): | ||
self.map = map | ||
self.object_storage = self.unboxed_storage = None | ||
|
||
|
||
class TestMapDict(BaseTopazTest): | ||
class TestMapDict(object): | ||
@pytest.mark.parametrize("i", range(10)) | ||
def test_simple_size_estimation(self, space, i): | ||
class_node = ClassNode(i) | ||
assert class_node.size_estimate() == 0 | ||
class_node = mapdict.ClassNode(i) | ||
assert class_node.size_estimate.object_size_estimate() == 0 | ||
assert class_node.size_estimate.unboxed_size_estimate() == 0 | ||
|
||
for j in range(1000): | ||
w_obj = FakeObject(class_node) | ||
for a in "abcdefghij"[:i]: | ||
w_obj.map.add_attr(space, w_obj, a) | ||
assert class_node.size_estimate() == i | ||
w_obj.map = w_obj.map.add(space, mapdict.ObjectAttributeNode, a, w_obj) | ||
assert class_node.size_estimate.object_size_estimate() == i | ||
assert class_node.size_estimate.unboxed_size_estimate() == 0 | ||
|
||
@pytest.mark.parametrize("i", range(1, 10)) | ||
def test_avg_size_estimation(self, space, i): | ||
class_node = ClassNode(i) | ||
assert class_node.size_estimate() == 0 | ||
class_node = mapdict.ClassNode(i) | ||
assert class_node.size_estimate.object_size_estimate() == 0 | ||
assert class_node.size_estimate.unboxed_size_estimate() == 0 | ||
|
||
for j in range(1000): | ||
w_obj = FakeObject(class_node) | ||
for a in "abcdefghij"[:i]: | ||
w_obj.map.add_attr(space, w_obj, a) | ||
w_obj.map = w_obj.map.add(space, mapdict.ObjectAttributeNode, a, w_obj) | ||
w_obj = FakeObject(class_node) | ||
for a in "klmnopqars": | ||
w_obj.map.add_attr(space, w_obj, a) | ||
assert class_node.size_estimate() in [(i + 10) // 2, (i + 11) // 2] | ||
w_obj.map = w_obj.map.add(space, mapdict.ObjectAttributeNode, a, w_obj) | ||
|
||
assert class_node.size_estimate.object_size_estimate() in [(i + 10) // 2, (i + 11) // 2] | ||
assert class_node.size_estimate.unboxed_size_estimate() == 0 |
Oops, something went wrong.