benchmarks: Added benchmarks for C, Go, Ruby, Python and Nit
authorLucas Bajolet <r4pass@hotmail.com>
Thu, 10 Dec 2015 20:47:27 +0000 (15:47 -0500)
committerLucas Bajolet <r4pass@hotmail.com>
Tue, 15 Dec 2015 15:37:19 +0000 (10:37 -0500)
Signed-off-by: Lucas Bajolet <r4pass@hotmail.com>

benchmarks/json/scripts/c_parser.c [new file with mode: 0644]
benchmarks/json/scripts/json_ext.rb [new file with mode: 0644]
benchmarks/json/scripts/json_parse.go [new file with mode: 0644]
benchmarks/json/scripts/json_pure.rb [new file with mode: 0644]
benchmarks/json/scripts/nit_adhoc_utf_noropes.nit [new file with mode: 0644]
benchmarks/json/scripts/nit_adhoc_utf_ropes.nit [new file with mode: 0644]
benchmarks/json/scripts/nitcc_parser.nit [new file with mode: 0644]
benchmarks/json/scripts/python.py [new file with mode: 0644]

diff --git a/benchmarks/json/scripts/c_parser.c b/benchmarks/json/scripts/c_parser.c
new file mode 100644 (file)
index 0000000..dfaf745
--- /dev/null
@@ -0,0 +1,48 @@
+#include "ujdecode.c"
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <assert.h>
+
+// Gets the byte size of a file
+int file_byte_size(char* path)
+{
+       int f = open(path, O_RDONLY);
+       if(f == -1)
+               return -1;
+       struct stat s;
+       int ln = 0;
+       if(!fstat(f, &s))
+               ln = s.st_size;
+       close(f);
+       return ln;
+}
+
+int main(int argc, char** argv)
+{
+       if(argc == 1) {
+               printf("Usage: ./c_parser file\n");
+               exit(1);
+       }
+
+       int fl_sz = file_byte_size(argv[1]);
+       char* input = malloc(fl_sz);
+
+       FILE* ifl = fopen(argv[1], "r");
+       if(ifl == NULL) {
+               printf("Error: cannot read file %s, are you sure permissions are set correctly ?\n", argv[1]);
+               exit(2);
+       }
+       int rd = fread(input, 1, fl_sz, ifl);
+       assert(rd == fl_sz);
+
+       void *state;
+
+       UJObject obj = UJDecode(input, fl_sz, NULL, &state);
+
+       free(input);
+       UJFree(state);
+}
diff --git a/benchmarks/json/scripts/json_ext.rb b/benchmarks/json/scripts/json_ext.rb
new file mode 100644 (file)
index 0000000..5c87062
--- /dev/null
@@ -0,0 +1,4 @@
+require 'json/ext'
+
+txt = IO.read(ARGV.first)
+my_hash = JSON.parse(txt)
diff --git a/benchmarks/json/scripts/json_parse.go b/benchmarks/json/scripts/json_parse.go
new file mode 100644 (file)
index 0000000..949a908
--- /dev/null
@@ -0,0 +1,20 @@
+package main
+
+import "io/ioutil"
+import "encoding/json"
+import "os"
+import "fmt"
+
+func main() {
+       if len(os.Args) == 1 {
+               fmt.Println("Usage ./json_parse file")
+               os.Exit(-1)
+       }
+       dat, err := ioutil.ReadFile(os.Args[1])
+       if err != nil { panic(err) }
+
+       var obj interface{}
+
+       jsonerr := json.Unmarshal(dat, &obj)
+       if jsonerr != nil { panic(jsonerr) }
+}
diff --git a/benchmarks/json/scripts/json_pure.rb b/benchmarks/json/scripts/json_pure.rb
new file mode 100644 (file)
index 0000000..2630cfd
--- /dev/null
@@ -0,0 +1,4 @@
+require 'json/pure'
+
+txt = IO.read(ARGV.first)
+my_hash = JSON.parse(txt)
diff --git a/benchmarks/json/scripts/nit_adhoc_utf_noropes.nit b/benchmarks/json/scripts/nit_adhoc_utf_noropes.nit
new file mode 100644 (file)
index 0000000..025a2e4
--- /dev/null
@@ -0,0 +1,18 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import json::string_parser
+
+var text = args.first.to_path.read_all_bytes.to_s
+var json = text.parse_json
diff --git a/benchmarks/json/scripts/nit_adhoc_utf_ropes.nit b/benchmarks/json/scripts/nit_adhoc_utf_ropes.nit
new file mode 100644 (file)
index 0000000..75e1046
--- /dev/null
@@ -0,0 +1,21 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import json::string_parser
+
+var f = new FileReader.open(args.first)
+
+var text = f.read_all
+f.close
+var json = text.parse_json
diff --git a/benchmarks/json/scripts/nitcc_parser.nit b/benchmarks/json/scripts/nitcc_parser.nit
new file mode 100644 (file)
index 0000000..f09b746
--- /dev/null
@@ -0,0 +1,18 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import json
+
+var text = args.first.to_path.read_all
+var json = text.parse_json
diff --git a/benchmarks/json/scripts/python.py b/benchmarks/json/scripts/python.py
new file mode 100644 (file)
index 0000000..b8417e4
--- /dev/null
@@ -0,0 +1,5 @@
+import sys
+import json
+
+json_data=open(sys.argv[1]).read()
+data = json.loads(json_data)