def test_shallow_and_large(self): key = self.KEY + ("shallow+large", ) item = ShallowRoot(scale=100) self._reset_buffer() with timed() as t: aioxmpp.xml.write_single_xso(item, self.buf) record(key + ("sz", ), self.buf.tell(), "B") record(key + ("rate", ), self.buf.tell() / t.elapsed, "B/s")
def test_deep(self, iteration=None): key = self.KEY + ("deep", ) item = self.deep_samples[iteration % len(self.deep_samples)] self._reset_buffer() with timed() as t: aioxmpp.xml.write_single_xso(item, self.buf) record(key + ("sz", ), self.buf.tell(), "B") record(key + ("rate", ), self.buf.tell() / t.elapsed, "B/s")
def test_deep(self, iteration=None): key = self.KEY + ("deep",) item = self.deep_samples[iteration % len(self.deep_samples)] self._reset_buffer() with timed() as t: aioxmpp.xml.write_single_xso(item, self.buf) record(key+("sz",), self.buf.tell(), "B") record(key+("rate",), self.buf.tell() / t.elapsed, "B/s")
def test_shallow_and_large(self): key = self.KEY + ("shallow+large",) item = ShallowRoot(scale=100) self._reset_buffer() with timed() as t: aioxmpp.xml.write_single_xso(item, self.buf) record(key+("sz",), self.buf.tell(), "B") record(key+("rate",), self.buf.tell() / t.elapsed, "B/s")
def test_exhaustive_dualchar(self): validate = aioxmpp.xml.xmlValidateNameValue_str strs = ["x" + chr(cp) for cp in range(0, 0xd800)] with timed() as timer: for s in strs: validate(s) record(self.KEY + ("exhaustive_dualchar",), timer.elapsed / (len(strs)), "s")
def test_random_strings(self): key = self.KEY + ("random",) validate = aioxmpp.xml.xmlValidateNameValue_str rng = random.Random(1) samples = [] for i in range(1000): samples.append(base64.b64encode( random.getrandbits(120).to_bytes(120//8, 'little') ).decode("ascii").rstrip("=")) for sample in samples: with timed() as timer: validate(sample) record(key, timer.elapsed, "s")
def test_inserts(self): key = self.KEY + ("inserts", ) N = 1000 lru_dict = aioxmpp.cache.LRUDict() lru_dict.maxsize = N keys = [object() for i in range(N)] for i in range(N): lru_dict[keys[i]] = object() with timed() as t: for i in range(N): lru_dict[object()] = object() record(key, t.elapsed, "s")
def test_random_access(self): key = self.KEY + ("random_access", ) N = 1000 lru_dict = aioxmpp.cache.LRUDict() lru_dict.maxsize = N keys = [object() for i in range(N)] for i in range(N): lru_dict[keys[i]] = object() with timed() as t: for i in range(N): lru_dict[keys[random.randrange(0, N)]] record(key, t.elapsed, "s")
def test_inserts(self): key = self.KEY + ("inserts",) N = 1000 lru_dict = aioxmpp.cache.LRUDict() lru_dict.maxsize = N keys = [object() for i in range(N)] for i in range(N): lru_dict[keys[i]] = object() with timed() as t: for i in range(N): lru_dict[object()] = object() record(key, t.elapsed, "s")
def test_random_access(self): key = self.KEY + ("random_access",) N = 1000 lru_dict = aioxmpp.cache.LRUDict() lru_dict.maxsize = N keys = [object() for i in range(N)] for i in range(N): lru_dict[keys[i]] = object() with timed() as t: for i in range(N): lru_dict[keys[random.randrange(0, N)]] record(key, t.elapsed, "s")
def test_exhaustive(self): validate = aioxmpp.xml.xmlValidateNameValue_str r1 = range(0, 0xd800) r2 = range(0xe000, 0xf0000) range_iter = itertools.chain( # exclude surrogates r1, r2, ) with timed() as timer: for cp in range_iter: validate(chr(cp)) record(self.KEY + ("exhaustive",), timer.elapsed / (len(r1) + len(r2)), "s")