Last active
August 29, 2015 13:56
-
-
Save sudix/9203904 to your computer and use it in GitHub Desktop.
for benchmark
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
package main | |
//http://blog.safariflow.com/2013/02/22/go-as-an-alternative-to-node-js-for-very-fast-servers/ | |
import "net/http" | |
func main() { | |
bytes := make([]byte, 1024*1024) | |
for i := 0; i < len(bytes); i++ { | |
bytes[i] = 100 | |
} | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
w.Write(bytes) | |
}) | |
http.ListenAndServe(":8000", nil) | |
} |
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
http = require('http') | |
Buffer = require('buffer').Buffer; | |
n = 1024*1024; | |
b = new Buffer(n); | |
for (var i = 0; i < n; i++) b[i] = 100; | |
http.createServer(function (req, res) { | |
res.writeHead(200); | |
res.end(b); | |
}).listen(8000); |
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
package jp.sudix.finagle.benchmark | |
import com.twitter.finagle.Service | |
import com.twitter.finagle.http.Http | |
import com.twitter.util.Future | |
import com.twitter.finagle.builder.ServerBuilder | |
import org.jboss.netty.handler.codec.http.{DefaultHttpResponse, HttpVersion, HttpResponseStatus, HttpRequest, HttpResponse} | |
import org.jboss.netty.buffer.ChannelBuffers.copiedBuffer | |
import java.net.{SocketAddress, InetSocketAddress} | |
object Main { | |
def main(args: Array[String]) { | |
val bytes: Array[Byte] = Array.fill(1024*1024)(100:Byte) | |
val cb = copiedBuffer(bytes) | |
val response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK) | |
response.setContent(cb) | |
val service = new Service[HttpRequest, HttpResponse] { | |
def apply(request: HttpRequest) = { | |
Future.value(response) | |
} | |
} | |
val address: SocketAddress = new InetSocketAddress(8000) | |
ServerBuilder() | |
.codec(Http()) | |
.bindTo(address) | |
.name("HttpServer") | |
.build(service) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment