Last active
January 15, 2016 16:00
-
-
Save s-u/4efb284e3c15c6a2db16 to your computer and use it in GitHub Desktop.
Java JSON data frame test example
This file contains 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 characters
// simple test case for generating a test data frame in Java in JSON and native form | |
// uses Java Jsonx API, e.g., compile with -cp javax.json-api-1.0.jar:javax.json-1.0.4.jar | |
import javax.json.*; | |
public class A { | |
public static int n = 1000000; | |
public static void main(String[] main) { | |
JsonObjectBuilder ob = Json.createObjectBuilder(); | |
JsonArrayBuilder b = Json.createArrayBuilder(); | |
for (int i = 0; i < n; i++) b.add(i/5.); | |
ob.add("V1", b); | |
b = Json.createArrayBuilder(); | |
for (int i = 0; i < n; i++) b.add("X"+ (i % 10)); | |
ob.add("V2", b); | |
JsonObject model = ob.build(); | |
JsonWriter jsonWriter = Json.createWriter(System.out); | |
jsonWriter.writeObject(model); | |
jsonWriter.close(); | |
} | |
public static Object[] direct() { | |
double d[] = new double[n]; | |
for (int i = 0; i < n; i++) d[i] = i/5.; | |
String s[] = new String[n]; | |
for (int i = 0; i < n; i++) s[i] = "X" + (i % 10); | |
return new Object[] { d, s }; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment