Ejemplo n.º 1
0
    def test_walk(self):
        test_obj = None
        with time_it("create"):
            test_obj = create_test_object(
                3, 40, do_list=True, uvals=True,
                ukeys=True)  # 30 for fast, 50 for slower

        with time_it("deepcopy"):
            o1 = copy.deepcopy(test_obj)

        import simplejson, json
        with time_it("simplejson.dumps"):
            oj = simplejson.dumps(test_obj)
        log.info("  len(json): %s", len(oj))

        with time_it("json.dumps"):
            oj = json.dumps(test_obj)

        with time_it("simplejson.loads"):
            o2 = simplejson.loads(oj)

        with time_it("json.loads"):
            o2 = json.loads(oj)

        def unicode_to_utf8(value):
            if isinstance(value, unicode):
                value = str(value.encode('utf8'))
            return value

        from pyon.core.object import walk
        with time_it("pyon.core.object.walk / unicode"):
            o3 = walk(test_obj, unicode_to_utf8)

        with time_it("walk1 / unicode"):
            o4 = walk1(test_obj, unicode_to_utf8)

        from pyon.util.containers import recursive_encode
        o2 = simplejson.loads(oj)
        with time_it("pyon.util.containers.recursive_utf8encode"):
            recursive_encode(o2)

        o2 = simplejson.loads(oj)
        with time_it("recursive_utf8encode1"):
            recursive_encode1(o2)
Ejemplo n.º 2
0
    def test_walk(self):
        test_obj = None
        with time_it("create"):
            test_obj = create_test_object(3, 40, do_list=True, uvals=True, ukeys=True)  # 30 for fast, 50 for slower

        with time_it("deepcopy"):
            o1 = copy.deepcopy(test_obj)

        import simplejson, json
        with time_it("simplejson.dumps"):
            oj = simplejson.dumps(test_obj)
        log.info("  len(json): %s", len(oj))

        with time_it("json.dumps"):
            oj = json.dumps(test_obj)

        with time_it("simplejson.loads"):
            o2 = simplejson.loads(oj)

        with time_it("json.loads"):
            o2 = json.loads(oj)

        def unicode_to_utf8(value):
            if isinstance(value, unicode):
                value = str(value.encode('utf8'))
            return value

        from pyon.core.object import walk
        with time_it("pyon.core.object.walk / unicode"):
            o3 = walk(test_obj, unicode_to_utf8)

        with time_it("walk1 / unicode"):
            o4 = walk1(test_obj, unicode_to_utf8)

        from pyon.util.containers import recursive_encode
        o2 = simplejson.loads(oj)
        with time_it("pyon.util.containers.recursive_utf8encode"):
            recursive_encode(o2)

        o2 = simplejson.loads(oj)
        with time_it("recursive_utf8encode1"):
            recursive_encode1(o2)
Ejemplo n.º 3
0
    def test_walk(self):
        t1 = time.time()
        test_obj = create_test_object(3, 40, do_list=True, uvals=True, ukeys=True)  # 30 for fast, 50 for slower
        t2 = time.time()
        log.info("Time create: %s", (t2-t1))

        t1 = time.time()
        o1 = copy.deepcopy(test_obj)
        t2 = time.time()
        log.info("Time deepcopy: %s", (t2-t1))

        import simplejson
        t1 = time.time()
        oj = simplejson.dumps(test_obj)
        t2 = time.time()
        log.info("Time simplejson.dumps: %s", (t2-t1))
        log.info("  len(json): %s", len(oj))

        import json
        t1 = time.time()
        oj = json.dumps(test_obj)
        t2 = time.time()
        log.info("Time json.dumps: %s", (t2-t1))

        t1 = time.time()
        o2 = simplejson.loads(oj)
        t2 = time.time()
        log.info("Time simplejson.loads: %s", (t2-t1))

        t1 = time.time()
        o2 = json.loads(oj)
        t2 = time.time()
        log.info("Time json.loads: %s", (t2-t1))

        def unicode_to_utf8(value):
            if isinstance(value, unicode):
                value = str(value.encode('utf8'))
            return value

        from pyon.core.object import walk
        t1 = time.time()
        o3 = walk(test_obj, unicode_to_utf8)
        t2 = time.time()
        log.info("Time pyon.core.object.walk / unicode: %s", (t2-t1))

        t1 = time.time()
        o4 = walk1(test_obj, unicode_to_utf8)
        t2 = time.time()
        log.info("Time walk1 / unicode: %s", (t2-t1))

        from pyon.util.containers import recursive_encode
        o2 = simplejson.loads(oj)
        t1 = time.time()
        recursive_encode(o2)
        t2 = time.time()
        log.info("Time pyon.util.containers.recursive_utf8encode: %s", (t2-t1))

        o2 = simplejson.loads(oj)
        t1 = time.time()
        recursive_encode1(o2)
        t2 = time.time()
        log.info("Time recursive_utf8encode1: %s", (t2-t1))
Ejemplo n.º 4
0
 def read_doc_mult(self, object_ids, strict=True):
     objs = self.obj_store.read_doc_mult(object_ids, strict=strict)
     objs = [recursive_encode(obj) if obj is not None else None for obj in objs]
     return objs
Ejemplo n.º 5
0
 def read_doc(self, doc_id):
     obj = self.obj_store.read_doc(doc_id)
     obj = obj.copy()
     recursive_encode(obj)
     return obj
Ejemplo n.º 6
0
 def read_doc_mult(self, object_ids, strict=True):
     objs = self.obj_store.read_doc_mult(object_ids, strict=strict)
     objs = [
         recursive_encode(obj) if obj is not None else None for obj in objs
     ]
     return objs
Ejemplo n.º 7
0
 def read_doc(self, doc_id):
     obj = self.obj_store.read_doc(doc_id)
     obj = obj.copy()
     recursive_encode(obj)
     return obj