[Piglit] [PATCH] Use simplejson if available

Dylan Baker baker.dylan.c at gmail.com
Wed Oct 16 04:30:31 CEST 2013


simplejson is a native code version of the json module in python
(the json module in core python implements the simplejson api), which
means that simplejson can be used in place of the json module, but it
performs much better. This patch attempts to load simplejson, and falls
back to normal json if it fails.

In the summary path on a single run of quick.tests, simplejson is about
3-4 seconds faster than json, ~7 seconds vs ~11 seconds.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/core.py          | 5 ++++-
 framework/shader_test.py   | 5 ++++-
 framework/tests/summary.py | 5 ++++-
 glapi/parse_glspec.py      | 5 ++++-
 piglit-print-commands.py   | 1 -
 piglit-run.py              | 1 -
 tests/util/gen_dispatch.py | 5 ++++-
 7 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index db28cfb..4426f41 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -23,7 +23,6 @@
 # Piglit core
 
 import errno
-import json
 import os
 import platform
 import re
@@ -39,6 +38,10 @@ from textwrap import dedent
 from threads import synchronized_self
 import threading
 import multiprocessing
+try:
+    import simplejson as json
+except ImportError:
+    import json
 
 from threadpool import ThreadPool
 
diff --git a/framework/shader_test.py b/framework/shader_test.py
index 82820fd..ea1d462 100755
--- a/framework/shader_test.py
+++ b/framework/shader_test.py
@@ -23,7 +23,10 @@
 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
-import json
+try:
+    import simplejson as json
+except ImportError:
+    import json
 import os
 import os.path
 import os.path as path
diff --git a/framework/tests/summary.py b/framework/tests/summary.py
index 194580c..de67c1d 100644
--- a/framework/tests/summary.py
+++ b/framework/tests/summary.py
@@ -24,11 +24,14 @@
 
 import os
 import os.path as path
-import json
 import unittest
 import itertools
 import tempfile
 
+try:
+    import simplejson as json
+except ImportError:
+    import json
 import framework.summary as summary
 from helpers import test_iterations, create_testresult, create_test
 
diff --git a/glapi/parse_glspec.py b/glapi/parse_glspec.py
index 2a8f73a..bab4996 100644
--- a/glapi/parse_glspec.py
+++ b/glapi/parse_glspec.py
@@ -118,9 +118,12 @@
 
 import collections
 import csv
-import json
 import re
 import sys
+try:
+    import simplejson as json
+except ImportError:
+    import json
 
 
 GLSPEC_HEADER_REGEXP = re.compile(r'^(\w+)\((.*)\)$')
diff --git a/piglit-print-commands.py b/piglit-print-commands.py
index c363fa1..c42ea6d 100755
--- a/piglit-print-commands.py
+++ b/piglit-print-commands.py
@@ -28,7 +28,6 @@ import os
 import os.path as path
 import time
 import traceback
-import json
 
 sys.path.append(path.dirname(path.realpath(sys.argv[0])))
 import framework.core as core
diff --git a/piglit-run.py b/piglit-run.py
index 4c87187..7321a23 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -28,7 +28,6 @@ import os
 import os.path as path
 import time
 import traceback
-import json
 
 sys.path.append(path.dirname(path.realpath(sys.argv[0])))
 import framework.core as core
diff --git a/tests/util/gen_dispatch.py b/tests/util/gen_dispatch.py
index 10b5dc5..c97af94 100644
--- a/tests/util/gen_dispatch.py
+++ b/tests/util/gen_dispatch.py
@@ -143,9 +143,12 @@
 #   function corresponding to each entry in function_names.
 
 import collections
-import json
 import os.path
 import sys
+try:
+    import simplejson as json
+except:
+    import json
 
 
 # Generate a top-of-file comment cautioning that the file is
-- 
1.8.1.5



More information about the Piglit mailing list