Last active
October 31, 2022 08:27
-
-
Save Gsantomaggio/921d2de9d1c751f6b3b4bfecca4e6a9d to your computer and use it in GitHub Desktop.
Revisions
-
Gsantomaggio revised this gist
Oct 30, 2022 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,11 +24,11 @@ def default(self, o): start_time = time.time() x = 1_000_000 for n in range(x): foo = Foo("String_1", "string_2", 123) foo_nested = FooWithNested(n + 100, n, foo) json_string = FooEncoder().encode(foo_nested) obj = json.loads(json_string, cls=json.JSONDecoder) -
Gsantomaggio revised this gist
Oct 30, 2022 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,6 @@ def default(self, o): foo_nested = FooWithNested(x + 100, x, 123) foo = Foo("String_1", "string_2", foo_nested) json_string = FooEncoder().encode(foo) obj = json.loads(json_string, cls=json.JSONDecoder) -
Gsantomaggio created this gist
Oct 30, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ import json import time from json import JSONEncoder class Foo: def __init__(self, string_1, string_2, int_1): self.string_1 = string_1 self.string_1 = string_2 self.int_1 = int_1 class FooWithNested: def __init__(self, int64_2, int64_1, foo_nested_): self.int64_2 = int64_2 self.int64_1 = int64_1 self.foo_nested = foo_nested_ # subclass JSONEncoder class FooEncoder(JSONEncoder): def default(self, o): return o.__dict__ start_time = time.time() x = 100_000 for n in range(x): foo_nested = FooWithNested(x + 100, x, 123) foo = Foo("String_1", "string_2", foo_nested) json_string = FooEncoder().encode(foo) employeeJSONData = json.dumps(foo, indent=4, cls=FooEncoder) obj = json.loads(json_string, cls=json.JSONDecoder) txt2 = "Seconds: {0}, iterations: {1}".format((time.time() - start_time), x) print(txt2)