All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.fastjson2.example.graalvm_native.App Maven / Gradle / Ivy

The newest version!
package com.alibaba.fastjson2.example.graalvm_native;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.example.graalvm_native.vo.MediaContent;

public class App {
    public static void main(String[] args) throws Exception {
        String str = "{\"images\": [{\n" +
                "      \"height\":768,\n" +
                "      \"size\":\"LARGE\",\n" +
                "      \"title\":\"Javaone Keynote\",\n" +
                "      \"uri\":\"http://javaone.com/keynote_large.jpg\",\n" +
                "      \"width\":1024\n" +
                "    }, {\n" +
                "      \"height\":240,\n" +
                "      \"size\":\"SMALL\",\n" +
                "      \"title\":\"Javaone Keynote\",\n" +
                "      \"uri\":\"http://javaone.com/keynote_small.jpg\",\n" +
                "      \"width\":320\n" +
                "    }\n" +
                "  ],\n" +
                "  \"media\": {\n" +
                "    \"bitrate\":262144,\n" +
                "    \"duration\":18000000,\n" +
                "    \"format\":\"video/mpg4\",\n" +
                "    \"height\":480,\n" +
                "    \"persons\": [\n" +
                "      \"Bill Gates\",\n" +
                "      \"Steve Jobs\"\n" +
                "    ],\n" +
                "    \"player\":\"JAVA\",\n" +
                "    \"size\":58982400,\n" +
                "    \"title\":\"Javaone Keynote\",\n" +
                "    \"uri\":\"http://javaone.com/keynote.mpg\",\n" +
                "    \"width\":640\n" +
                "  }\n" +
                "}";

        MediaContent mediaContent = JSON.parseObject(str, MediaContent.class);

        int LOOP_COUNT = 1000000;
        for (int j = 0; j < 5; ++j) {
            long start = System.currentTimeMillis();
            for (int i = 0; i < LOOP_COUNT; i++) {
                JSON.toJSONString(mediaContent);
            }
            long millis = System.currentTimeMillis() - start;
            System.out.println("fastjson2 eishay toJSONString time : " + millis);
        }
        for (int j = 0; j < 5; ++j) {
            long start = System.currentTimeMillis();
            for (int i = 0; i < LOOP_COUNT; i++) {
                JSON.parseObject(str, MediaContent.class);
            }
            long millis = System.currentTimeMillis() - start;
            System.out.println("fastjson2 eishay parseObject time : " + millis);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy