浏览代码

add benchmark for item attribute / dict access

Author: @RonnyPfannschmidt in PR #5763
Thomas Waldmann 2 年之前
父节点
当前提交
7b3cdb1aea
共有 1 个文件被更改,包括 15 次插入0 次删除
  1. 15 0
      src/borg/testsuite/benchmark.py

+ 15 - 0
src/borg/testsuite/benchmark.py

@@ -11,6 +11,7 @@ import os
 import pytest
 
 from .archiver import changedir, cmd
+from .item import Item
 from ..constants import zeros
 
 
@@ -108,3 +109,17 @@ def test_check(benchmark, cmd, repo_archive):
 def test_help(benchmark, cmd):
     result, out = benchmark(cmd, "help")
     assert result == 0
+
+
+@pytest.mark.parametrize("type, key, value", [(Item, "size", 1000), (Item, "mode", 0x777), (Item, "deleted", False)])
+def test_propdict_attributes(benchmark, type, key, value):
+
+    propdict = type()
+
+    def getattr_setattr(item, key, value):
+        setattr(item, key, value)
+        assert item.get(key) == value
+        assert getattr(item, key) == value
+        item.as_dict()
+
+    benchmark(getattr_setattr, propdict, key, value)