TechEmpower Framework Benchmarks
基于TechEmpower的《Web Framework Benchmarks》性能基准测试的解读之后
注:带星号的项目支持完整的ORM和模板技术
一、神奇的Lithium
C++和Rust都是只提供编译期反射的,所以实现ORM的方法有两种,一种是带生成器,需要工具和预处理。一种是利用宏和模板技术来生成代码。
Lithium这个项目和其它妖艳贱货不一样,代码优雅得一塌糊涂,而且性能惊人Lithium(ORM)(RAW)以 59.2%的成绩一骑绝尘。虽然使用宏和模板有点烧脑,但还是值得一看。
对比Rust的Diesel,仅取得了24%的成绩还是有很大提升空间的。Golang的框架测试代码中没有一个带ORM,是因为Golang的反射机制还是很慢的,直接拖累了性能。
auto fortunes = sql_orm_schema(sql_db, "Fortune").fields( s::id(s::auto_increment, s::primary_key) = int(), s::message = std::string()); my_api.get("/fortunes") = [&](http_request& request, http_response& response) { sql_db.max_async_connections_per_thread_ = fortunes_nconn; typedef decltype(fortunes.all_fields()) fortune; std::vector<fortune> table; { auto c = fortunes.connect(request.fiber); c.forall([&] (const auto& f) { table.emplace_back(metamap_clone(f)); }); } table.emplace_back(0, "Additional fortune added at request time."); std::sort(table.begin(), table.end(), [] (const fortune& a, const fortune& b) { return a.message < b.message; }); li::growing_output_buffer ss; ss << "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>"; for(auto& f : table) { ss << "<tr><td>" << f.id << "</td><td>"; escape_html_entities(ss, f.message); ss << "</td&g