Created
November 22, 2014 23:32
-
-
Save bodiam/e9c20a6d7f4e2a7aef33 to your computer and use it in GitHub Desktop.
AsciiDoc benchmark for JDK 1.6 and JDK 1.8
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
import javax.script.ScriptEngine; | |
import javax.script.ScriptEngineManager; | |
import javax.script.ScriptException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
public class Main { | |
public static void main(String[] args) throws IOException, ScriptException { | |
ScriptEngineManager manager = new ScriptEngineManager(); | |
ScriptEngine engine = manager.getEngineByName("nashorn"); | |
if(engine != null) { | |
System.out.println("Using Java 8 Nashorn"); | |
} else { | |
engine = manager.getEngineByName ("js"); | |
System.out.println("Using Java 6 Javascript"); | |
} | |
long beginTime = System.currentTimeMillis(); | |
FileReader opal = new FileReader("src/main/java/org/asciidoc/intellij/main/opal.js"); | |
FileReader asciidoctor = new FileReader("src/main/java/org/asciidoc/intellij/main/asciidoctor.js"); | |
engine.eval(opal); | |
engine.eval(asciidoctor); | |
for(int i =0; i < 10; i ++) { | |
System.out.println(engine.eval("asciidoctorDocument = Opal.Asciidoctor.$load(\"= Real-time collaborative editor for AsciiDoc\\nMaxime Greau \\x3Chttps:\\x2F\\x2Fgithub.com\\x2Fmgreau[@mgreau]\\x3E\\nv0.1.0.alpha4, March 16, 2014\\n:imagesdir: https:\\x2F\\x2Fraw.github.com\\x2Fmgreau\\x2Fwhen-websocket-met-asciidoctor\\x2Fmaster\\x2Fdoc\\x2Fimg\\x2F\\n:toc:\\n:toclevels: 3\\n:idseparator: -\\n:online-demo: http:\\x2F\\x2Fwildfly-mgreau.rhcloud.com\\x2Fad-editor\\n:milestones: https:\\x2F\\x2Fgithub.com\\x2Fmgreau\\x2Fwhen-websocket-met-asciidoctor\\x2Fissues\\x2Fmilestones\\n:issues: https:\\x2F\\x2Fgithub.com\\x2Fmgreau\\x2Fwhen-websocket-met-asciidoctor\\x2Fissues\\n:asciidoctor-url: http:\\x2F\\x2Fasciidoctor.org\\n:asciidoctorj-url: https:\\x2F\\x2Fgithub.com\\x2Fasciidoctor\\x2Fasciidoctorj\\n:asciidoctorjs-url: https:\\x2F\\x2Fgithub.com\\x2Fasciidoctor\\x2Fasciidoctor.js\\n:asciidoctor-backends-url: https:\\x2F\\x2Fgithub.com\\x2Fasciidoctor\\x2Fasciidoctor-backends\\n:wildfly-url: http:\\x2F\\x2Fdownload.jboss.org\\x2Fwildfly\\x2F8.0.0.Final\\x2Fwildfly-8.0.0.Final.zip\\n:demo-url: https:\\x2F\\x2Fraw.github.com\\x2Fmgreau\\x2Fwhen-websocket-met-asciidoctor\\x2Fmaster\\x2Fdoc\\x2Fdemo\\x2F\\n\\n== Overview\\n\\n.This project gives you the possibility to *work on the same AsciiDoc file with a team and see the rendering in realtime*.\\n\\nIt\\'s based on the {asciidoctor-url}[Asciidoctor project] thanks to : \\n\\n* the Java API provided by {asciidoctorj-url}[AsciidoctorJ]\\n* the Javascript libraries provided by {asciidoctorjs-url}[Asciidoctor.js]\\n\\n== How to test it ?\\n\\n. *Install it* quickly (0.1.0-alpha3)\\n \\n curl https:\\x2F\\x2Fraw.github.com\\x2Fmgreau\\x2Fwhen-websocket-met-asciidoctor\\x2Fmaster\\x2Finstall.sh | bash\\n \\n. or *try it online* at {online-demo} (running on OpenShift).\\n. or clone the project and follow the instructions below\\n\\n\\n[[collaborative-editor]]\\n.Demo Collaborative Editor\\nimage::..\\x2Fdemo\\x2Fcollaborative-editor.gif[Collaborative-editor, 600, link=\\\"{demo-url}collaborative-editor.gif\\\"]\\n\\nIf you have an existing asciidoc file, you can drag and drop this file to the editor :\\n\\n[[drag-drop]]\\n.Drag and drop feature\\nimage::ad-editor-dragdrop.png[Drag and drop feature, 600, link=\\\"{demo-url}ad-editor-dragdrop.png\\\"]\\n\\nYou can also work on an offline mode with just your browser :\\n\\n[[offline]]\\n.Offline mode feature\\nimage::ad-editor-offline.png[Offline mode feature, 600, link=\\\"{imagesdir}ad-editor-offline.png\\\"]\\n\\n== 0.1.0-alpha4-SNAPSHOT (dev in progress)\\n\\n* *+dzSlides backend+* : you can work on your slides for a presentation !\\n\\n\\n== 0.1.0-alpha3 - new features\\n\\n* +*Full offline mode+* : if you are not connected to the server by WebScoket protocol, then the\\nrendering view is still working in real-time with the Javascript project asciidoctor.js\\n* +*Drag and Drop*+ : you can *drag a AsciiDoc file* from your laptop and *drop it into the editor* and the content of the file\\nwill be loaded into the editor\\n\\n== 0.1.0-alpha2 new features\\n\\n* Create a *new space* OR *join others author* with a spaceID\\n* *Browser storage* with HTML5 IndexedDB for backup (save and load AsciiDoc source)\\n* *Fullscreen mode* for HTML5 preview\\n* Improved UI Design\\n* HTML5 preview in realtime : \\n** *each time the AsciiDoc source is changed* if you have clicked on +Render On Change+\\n** *each time you press \\\"Alt+R\\\"* if you have clicked on +Render On Alt+R+ button\\n* *Patch feature* :\\n** if an other author send a version, you can click on +Compute Diff+ button to see differences between your adoc file and the last adoc file\\n** if the patch seems ok, click on +Apply Patch+ and you adoc source will be up to date\\n* *Load the last AsciiDoc source* send by an other author\\n\\n[diff feature]\\n.Compute diff feature\\nimage::ad-editor-diff.png[Diff feature example, 600]\\n\\n[patch feature]\\n.patch feature\\nimage::ad-editor-patch.png[Patch feature example, 600]\\n\\n== Changelog\\n\\nYou can read all changes between each release in the link:CHANGELOG.adoc[changelog file].\\n\\n== Roadmap\\n\\nA lot of cool features are planned :) You can read all {issues}[open and closed issues] and {milestones}[milestones]\\n\\n== [DEV MODE] Install on your laptop\\n\\n[IMPORTANT]\\n.Prerequisites\\n====\\n* JDK 7\\n* Apache Maven 3.1\\n====\\n\\n. Clone or download this github project (*+$APP_HOME+*)\\n\\n. Installing the Java EE 7 Compliance App server \\n.. Download {wildfly-url}[WildFly 8.0.0-Final] (*+$JBOSS_HOME+*)\\n.. Then you need to deploy the link:module\\x2FREADME.adoc[Asciidoctor module] into your WildFly app server\\n.. For the slides features, you have to install {asciidoctor-backends-url}[asciidoctor-backends] into +$JBOSS_HOME\\x2Fstandalone\\x2Fdatas+\\n\\n. Installing Bower\\n.. Bower depends on Node and npm. It\\'s installed globally using npm:\\n \\n npm install -g bower\\n \\n.. Installing the bower dependencies needed by this app (into +$APP_HOME\\x2Fsrc\\x2Fmain\\x2Fwebapp\\x2Flibs+)\\n\\n cd $APP_HOME\\n bower install\\n \\n. Build the WAR and test it into WildFly AS with maven\\x2Farquillian : \\n\\n .. if the environement variable +$JBOSS_HOME+ is set :\\n\\n mvn clean package -Pwildfly-managed-arquillian\\n\\n .. if you haven\\'t set the +$JBOSS_HOME+ env variable :\\n\\n mvn clean package -Pwildfly-managed-arquillian -DserverRoot=\\x3Cpath_to_the_server\\x3E\\n \\n. Deploy the app automatically with maven : \\n\\n .. if the app server is started\\n \\n mvn wildfly:deploy -Dmaven.test.skip=true\\n \\n .. if the app server isn\\'t started\\n \\n mvn wildfly:run -Dmaven.test.skip=true -Djboss-as.home=\\x3Cpath_to_the_server\\x3E\\n\\n. Launch your browser and enjoy :)\\n\\n * http:\\x2F\\x2Flocalhost:8080\\x2Fad-editor\\n\\n\\n== Technology used\\n\\n* Asciidoctor project\\n** AsciidoctorJ 0.1.4\\n** asciidocor.js\\n* Java EE 7 \\n** CDI 1.1\\n** WebSocket 1.0\\n** JSON-P 1.0\\n** EJB 3.2\\n* Web Client\\n** AngularJS 1.2.11\\n** Ace Editor\\n** Bootstrap 3.0\\n* Tests\\n** JUnit 4.8\\n** Arquillian 1.1.2\\n* Java EE 7 Compliance App server\\n\\n\", Opal.hash2(['attributes'], {'attributes': 'showtitle toc2 showauthor icons=font@'}));\n" + | |
"asciidoctorDocument.$render();\n")); | |
} | |
long endTime = System.currentTimeMillis(); | |
System.out.println("Rendering took " + (endTime -beginTime) + " ms"); | |
} | |
} |
On a Mac (2.6 Ghz, i7, 16GB with MacOS 10.9.5)
Using 10 iterations:
// Rendering took 8255 ms using Java 6
// Rendering took 12174 ms using Java 8
Using 100 iterations:
// Rendering took 53567 ms using Java 8
// Rendering took 38389 ms using Java 6
Actually, that char bug is fixed in the latest Asciidoctor.js, but if you hold out for a few more days we'll have an even more stable version available (1.5.2).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Small remark: when using Java 6, you'll need to do a s/char/somethingElse/g on the opal.js