Markdownserver
Using simple ab (with concurrency):
$ ab -n 10000 -c 10 http://localhost:XXXX/markdown?body=THis+%2Ais%2A+a+string
Where XXXX
is the port number depending on which server you'rerunning.
Results:
Python (Flask) 2103.06 [#/sec] (mean)
Python (Tornado) 1834.48 [#/sec] (mean)
Node (Express) 4406.17 [#/sec] (mean)
Go 19539.61 [#/sec] (mean)
To run the Go version, first set your $GOPATH
then:
$ go get github.com/russross/blackfriday
$ go run main.go
$ curl http://localhost:8080/markdown?body=THis+%2Ais%2A+a+string
To run the Tornado versions:
$ virtualenv venv
$ source venv/bin/activate
$ pip install tornado mistune markdown
$ python tornado_.py
$ curl http://localhost:8888/markdown?body=THis+%2Ais%2A+a+string
To run the Flask version:
$ virtualenv venv
$ source venv/bin/activate
$ pip install Flask mistune markdown
$ python flask_.py
$ curl http://localhost:5000/markdown?body=THis+%2Ais%2A+a+string
To run the NodeJS version:
$ npm install # picks up from package.json
$ node node_.js
$ curl http://localhost:3000/markdown?body=THis+%2Ais%2A+a+string
Python
- try:
- import mistune as markdown
- except ImportError:
- import markdown # py implementation
- import falcon
- app = falcon.API()
- class Markdown:
- def on_get(self, req, resp):
- resp.body = markdown.markdown(req.get_param('body'))
- app.add_route('/markdown', Markdown())
- if __name__ == '__main__':
- from wsgiref import simple_server
- httpd = simple_server.make_server('127.0.0.1', 5000, app)
- httpd.serve_forever()
- try:
- import mistune as markdown
- except ImportError:
- import markdown # py implementation
- from flask import Flask, request
- app = Flask(__name__)
- import logging
- log = logging.getLogger('werkzeug')
- log.setLevel(logging.ERROR)
- @app.route("/markdown")
- def markdown_view():
- return markdown.markdown(request.args['body'])
- if __name__ == "__main__":
- app.run()
- import tornado
- try:
- import mistune as markdown
- except ImportError:
- import markdown # py implementation
- import tornado.ioloop
- import tornado.web
- class MarkdownHandler(tornado.web.RequestHandler):
- def get(self):
- body = self.get_argument('body')
- self.write(markdown.markdown(body))
- application = tornado.web.Application([
- (r"/markdown", MarkdownHandler),
- ])
- if __name__ == "__main__":
- application.listen(8888)
- tornado.ioloop.IOLoop.instance().start()
Go
- package main
- import (
- "net/http"
- "os"
- "github.com/russross/blackfriday"
- )
- func main() {
- port := os.Getenv("PORT")
- if port == "" {
- port = "8080"
- }
- http.HandleFunc("/markdown", GenerateMarkdown)
- http.ListenAndServe(":"+port, nil)
- }
- func GenerateMarkdown(rw http.ResponseWriter, r *http.Request) {
- markdown := blackfriday.MarkdownCommon(
- []byte(r.FormValue("body")))
- rw.Write(markdown)
- }