|
local lz4 = require "lz4" |
|
|
|
local zlib = require "zlib" |
|
|
|
local snappy = require "snappy" |
|
|
|
local zstd = require "zstd" |
|
|
|
local brotli = require "brotli" |
|
|
|
-- local text = [==[ |
|
-- 完善的异步I/O支持 |
|
-- 框架已经对网络、文件两种IO进行改造, 使内部的I/O全异步化成为可能. |
|
|
|
-- 框架自动化调度 |
|
-- 框架会在内部自动调度协程、定时器、I/O, 您也可以选择手动控制它. |
|
|
|
-- 丰富的内置库支持 |
|
-- 框架内部的提供了完整的内置库, 实现了基础应用全方面开发覆盖. |
|
|
|
-- 传输安全与加密 |
|
-- 提供近60多种加密/散列/签名等等算法, 并且内部已经支持SSL Server / Client. |
|
|
|
-- 数据交换格式支持 |
|
-- 您需要 JSON / PROTOBUF / XML / MSGPACK 吗? 那么非常幸运, 它们都提供好了! |
|
|
|
-- 内置协议多样化 |
|
-- 支持常见的 HTTP[S]/STOMP/SMTP/ Websocket 等协议. |
|
|
|
-- 自主重写异步客户端 |
|
-- 让我们可以随心所欲的使用. (Redis/MySQL/PGSQL/MSSQL) |
|
|
|
-- 合理的进程运行模式 |
|
-- 拆分工作进程与管理进程,运行模式更加准确且合理。 |
|
|
|
-- 资源的高效利用 |
|
-- 完美的将所有内存、核心数量都妥善使用。 |
|
|
|
-- 适用于各种部署场景 |
|
-- 无论虚拟化、容器、宿主机,这都是我们的主要战场. |
|
|
|
-- 带宽利用与性能优化 |
|
-- 传输数据压缩与数据库连接池的利用都不用手动维护 |
|
|
|
-- 强制化与规范化 |
|
-- 框架首先教您如何规范项目, 同样您也可以将其传授给挚友. |
|
-- ]==] |
|
|
|
-- local text = [==[ |
|
-- Advantage |
|
-- Asynchronous I/O - The Network I/O and File I/O have been transformed, and the internal operations are now fully asynchronous. |
|
|
|
-- Rich built-in libraries - Many complete built-in libraries are implemented to complete the development and coverage of all aspects of basic applications. |
|
|
|
-- Automated scheduling - The bottom layer will automatically schedule coroutines, timers and I/O, and you can also choose to control it manually. |
|
|
|
-- Security and Encryption - Provides nearly 60 kinds of hash/digest/hash/signature algorithms, and internally supports SSL Server/Client. |
|
|
|
-- Data Exchange Format - Do you need JSON / PROTOBUF / MSGPACK / BSON ? Great, they are all provided! |
|
|
|
-- Data Exchange Format - Do you need JSON / PROTOBUF / MSGPACK / BSON ? Great, they are all provided! |
|
|
|
-- Multi-database driver - MySQL / PGSQL / MSSQL / MongoDB are all available, you can also use it as you like. |
|
|
|
-- Multi-database driver - MySQL / PGSQL / MSSQL / MongoDB are all available, you can also use it as you like. |
|
|
|
-- Enforcement and standardization -The framework forces you to write code, and you can also pass it on to your close friends. |
|
|
|
-- Enforcement and standardization -The framework forces you to write code, and you can also pass it on to your close friends. |
|
-- ]==] |
|
|
|
local function test_f(f, data, n, v) |
|
local assert = assert |
|
for i = 1, n do |
|
assert(f(data, v)) |
|
end |
|
end |
|
|
|
local function calc_run(f, ...) |
|
local s = require "sys".time() |
|
f(...) |
|
local e = require "sys".time() |
|
return e - s |
|
end |
|
|
|
local n = 100000 |
|
|
|
local list = { |
|
{ name = 'zlib', compress = zlib.compress, uncompress = zlib.uncompress, data = zlib.compress(text), raw = text }, |
|
{ name = 'lz4', compress = lz4.compress, uncompress = lz4.uncompress, data = lz4.compress(text), raw = text, len = #text }, |
|
{ name = 'zstd', compress = zstd.compress, uncompress = zstd.uncompress, data = zstd.compress(text), raw = text }, |
|
{ name = 'brotli', compress = brotli.compress, uncompress = brotli.uncompress, data = brotli.compress(text), raw = text }, |
|
{ name = 'snappy', compress = snappy.compress, uncompress = snappy.uncompress, data = snappy.compress(text), raw = text }, |
|
} |
|
|
|
print("----") |
|
for _, obj in ipairs(list) do |
|
print(string.format("%s.compress %d 万次, 耗时: %f 秒", obj.name, n / 10000, calc_run(test_f, obj.compress, text, n))) |
|
end |
|
|
|
print("----") |
|
for _, obj in ipairs(list) do |
|
print(string.format("%s.uncompress %d 万次, 耗时: %f 秒", obj.name, n / 10000, calc_run(test_f, obj.uncompress, obj.data, n, obj.len))) |
|
end |
|
|
|
print("----") |
|
print('raw length = ', #text) |
|
local r = "" |
|
for _, obj in ipairs(list) do |
|
r = r .. string.format("%s compress length = %s, radiot = %.2f%%\n", obj.name, #obj.data, #obj.data / #text * 100) |
|
end |
|
print(r) |
|
print("----") |
|
print("End.") |