解决clearsilver 渲染cs_render慢
来源:互联网 发布:数学系的学不学编程 编辑:程序博客网 时间:2024/04/18 14:37
在使用 clearsilver去 渲染模板的时候,数据大了之后会明显慢很多,但是cs应该是非常高效的模板引擎,怎么会突然这么慢。
下面是cs的测试例子
#include <ClearSilver.h>#include <fstream>#include <iostream>#include <sstream>#include <string.h>#include <ctime>using namespace std;//从文件读入到string里string readFileIntoString(const char* filename){ ifstream ifile(filename); //将文件读入到ostringstream对象buf中 ostringstream buf; char ch; while(buf&&ifile.get(ch)) buf.put(ch); //返回与流对象buf关联的字符 return buf.str();}int i = 1;NEOERR *output(void *ctx, char *s){ string* x = (string*)ctx; // *x = *x + s; x->append(s); return STATUS_OK;}int main(){ printf("dssds\n"); const string htmlpath = "list_machine_error.html"; const string hdfpath = "list_machine_error.out"; clock_t time1 = clock(); string hdf_str = readFileIntoString(hdfpath.c_str() ); // printf("%s\n", hdf_str.c_str() ); clock_t time2 = clock(); printf("time1- %f\n", (double)(time2-time1) ); HDF* hdf; CSPARSE* parse; hdf_init(&hdf); clock_t time3 = clock(); printf("time2- %f\n", (double)(time3-time2) ); hdf_read_string(hdf, hdf_str.c_str() ); clock_t time4 = clock(); printf("time3- %f\n", (double)(time4-time3) ); cs_init(&parse, hdf); cs_parse_file(parse, htmlpath.c_str() ); clock_t time5 = clock(); printf("time4- %f\n", (double)(time5-time4) ); string result; cs_render(parse, &result, output); clock_t time6 = clock(); printf("time5- %f\n", (double)(time6-time5) ); // // printf("%s ", result.c_str() ); // string filepath2 = "my.html"; // ofstream fout2(filepath2.c_str() ); // fout2<<result<<endl;}
发现慢在cs_render 函数内
发现output函数中字符串拼接使用的 + 号
这里就得说字符串拼接了,对于大量的字符串拼接最好使用 append或者+= 类似java中的StringBuffer。
0 0
- 解决clearsilver 渲染cs_render慢
- clearsilver
- AE渲染加快速度,解决导出视频太慢的问题
- clearsilver 使用
- Java 图形渲染很慢
- ClearSilver模板编程总结
- Clearsilver应用文档
- ClearSilver模板编程:
- ClearSilver模板编程
- Clearsilver应用文档
- SSH慢解决
- 解决关机速度慢
- 解决phpMyadmin卡慢
- tomcat 变慢解决
- wordpress加载慢解决
- 解决数据库连接慢问题
- 解决eclipse启动慢
- Eclipse解决启动慢
- mybatis实战教程(mybatis in action)之一:开发环境搭建
- 多个列表切换使用同一个listview,切换时回到各个列表之前的位置
- [leetcode] Interleaving String
- Composite 设计模式
- 纯JS实现的3D标签云,不依赖任何第三方库,支持移动页面
- 解决clearsilver 渲染cs_render慢
- c#做端口转发程序支持正向连接和反向链接
- android经过POST和GET两种方式发送数据到web应用实战
- 最大公约数
- MySQL性能优化的21个最佳实践 和 mysql使用索引
- Centos 下 mount 共享文件夹,并分配权限给指定用户
- 机器学校自学建议
- 回溯法 -数据结构与算法
- 网络一直在测量臭氧以及其他几种污染物的水平。其中有三个监测站在香港。 QQ1458910822