Browse Source

Merge branch 'master' of github.com:TechEmpower/FrameworkBenchmarks

Patrick Falls 12 years ago
parent
commit
c4bc0bdea0

+ 24 - 1
play-java/.gitignore

@@ -4,4 +4,27 @@ project/target
 target
 target
 tmp
 tmp
 .history
 .history
-dist
+dist
+
+# Ignore all dotfiles...
+.*
+# except for .gitignore
+!.gitignore
+
+# Ignore Play! working directory #
+db
+eclipse
+lib
+log
+logs
+modules
+precompiled
+project/project
+project/target
+target
+tmp
+test-result
+server.pid
+*.iml
+*.eml
+

+ 38 - 27
play-java/app/controllers/Application.java

@@ -1,47 +1,58 @@
 package controllers;
 package controllers;
 
 
+import models.World;
+import play.libs.F;
 import play.libs.Json;
 import play.libs.Json;
-import play.mvc.*;
+
 import static play.libs.Akka.future;
 import static play.libs.Akka.future;
-import java.util.concurrent.Callable;
+
 import org.codehaus.jackson.node.ObjectNode;
 import org.codehaus.jackson.node.ObjectNode;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.map.ObjectMapper;
-import views.html.*;
-import models.*;
-import java.util.*;
-import java.util.concurrent.*;
+import play.mvc.Controller;
+import play.mvc.Result;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
 
 
 public class Application extends Controller {
 public class Application extends Controller {
 
 
     private static final int TEST_DATABASE_ROWS = 10000;
     private static final int TEST_DATABASE_ROWS = 10000;
     //http://stackoverflow.com/questions/3907929/should-i-make-jacksons-objectmapper-as-static-final
     //http://stackoverflow.com/questions/3907929/should-i-make-jacksons-objectmapper-as-static-final
-    private static ObjectMapper objectMapper = new ObjectMapper();
+    private static final ObjectMapper objectMapper = new ObjectMapper();
 
 
     public static Result json() {
     public static Result json() {
-        return async(
-          future(new Callable<Result>() {
-              public Result call() {
-                  ObjectNode result = objectMapper.createObjectNode();
-                  result.put("message", "Hello World!");
-                  return ok(result);
-              }
-          })
-        );
+        final ObjectNode result = objectMapper.createObjectNode();
+        result.put("message", "Hello World!");
+        return ok(result);
     }
     }
 
 
     public static Result db(final Integer queries) {
     public static Result db(final Integer queries) {
         return async(
         return async(
-          future(new Callable<Result>() {
-              public Result call() {
-                  final Random random = ThreadLocalRandom.current();
-                  final World[] worlds = new World[queries];
-
-                  for (int i = 0; i < queries; i++) {
-                      worlds[i] = World.find.byId((long)(random.nextInt(TEST_DATABASE_ROWS) + 1));
-                  }
-                  return ok(Json.toJson(worlds));
-              }
-          })
+                future(new Callable<Result>() {
+                    @Override
+                    public Result call() {
+                        final Random random = ThreadLocalRandom.current();
+                        final List<F.Promise<? extends World>> promises = new ArrayList<F.Promise<? extends World>>(queries);
+                        for (int i = 0; i < queries; ++i) {
+                            promises.add(future(findWorld(Long.valueOf(random.nextInt(TEST_DATABASE_ROWS) + 1))));
+                        }
+                        final List<World> worlds = F.Promise.sequence(promises).get(5L * queries, TimeUnit.SECONDS);
+                        return ok(Json.toJson(worlds));
+                    }
+
+                    private Callable<World> findWorld(final Long id) {
+                        return new Callable<World>() {
+                            @Override
+                            public World call() {
+                                return World.find.byId(id);
+                            }
+                        };
+                    }
+                })
         );
         );
 
 
     }
     }

+ 10 - 13
play-java/app/models/World.java

@@ -1,23 +1,20 @@
 package models;
 package models;
 
 
-import java.util.*;
 import javax.persistence.*;
 import javax.persistence.*;
 
 
 import play.db.ebean.*;
 import play.db.ebean.*;
-import play.data.format.*;
-import play.data.validation.*;
 
 
-@Entity 
+@Entity
 public class World extends Model {
 public class World extends Model {
 
 
-  @Id
-  public Long id;
-  
-  @Column(name = "randomNumber")
-  public Long randomNumber;
-  
-  public static Finder<Long,World> find = new Finder<Long,World>(
-    Long.class, World.class
-  ); 
+    @Id
+    public Long id;
+
+    @Column(name = "randomNumber")
+    public Long randomNumber;
+
+    public static Finder<Long, World> find = new Finder<Long, World>(
+            Long.class, World.class
+    );
 
 
 }
 }

+ 1 - 1
play-java/project/plugins.sbt

@@ -5,4 +5,4 @@ logLevel := Level.Warn
 resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
 resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
 
 
 // Use the Play sbt plugin for Play projects
 // Use the Play sbt plugin for Play projects
-addSbtPlugin("play" % "sbt-plugin" % "2.1.0")
+addSbtPlugin("play" % "sbt-plugin" % "2.1.1")

+ 24 - 1
play-scala/.gitignore

@@ -7,4 +7,27 @@ test
 tmp
 tmp
 .history
 .history
 dist
 dist
-conf/evolutions
+conf/evolutions
+
+# Ignore all dotfiles...
+.*
+# except for .gitignore
+!.gitignore
+
+# Ignore Play! working directory #
+db
+eclipse
+lib
+log
+logs
+modules
+precompiled
+project/project
+project/target
+target
+tmp
+test-result
+server.pid
+*.iml
+*.eml
+