//cocos 修改代码

.....

//性能测试代码

extern "C" {

#include <time.h>

#include <stdlib.h>

#include <stdio.h>

void ptest(){

auto TimeDiff = [](std::function<void()> func,const char* msg){

clock_t t1 , t2;

t1 = clock();

func();

t2 = clock();

CCLOG(msg,t2-t1);

};

auto writef = [](const char* path,int len){

FILE* fp = fopen(path, "wr+");

unsigned char* c = (unsigned char*)malloc(len);

memset(c, 'T', len);

fwrite(c, 1, len, fp);

fflush(fp);

fclose(fp);

fp =nullptr;

};

auto readfile = [](const char* path){

std::string src("src/ptest/datas/");

src.append(path);

FileUtils::getInstance()->getStringFromFile(src);

};

auto readfilea = [](const char* path){

std::string src(FileUtils::getInstance()->getWritablePath());

src.append("/");

src.append(path);

FileUtils::getInstance()->getStringFromFile(src);

};

std::string writepath = FileUtils::getInstance()->getWritablePath();

auto fullpath = [](std::string path,const char* str){ path.append(str); return path; };

writef(fullpath(writepath,"128B.s").c_str(),128);

writef(fullpath(writepath,"512B.s").c_str(),512);

writef(fullpath(writepath,"2K.s").c_str(),2*1024);

writef(fullpath(writepath,"4K.s").c_str(),4*1024);

writef(fullpath(writepath,"16K.s").c_str(),16*1024);

writef(fullpath(writepath,"512K.s").c_str(),512*1024);

writef(fullpath(writepath,"1M.s").c_str(),1*1024*1024);

writef(fullpath(writepath,"2M.s").c_str(),2*1024*1024);

writef(fullpath(writepath,"5M.s").c_str(),5*1024*1024);

writef(fullpath(writepath,"10M.s").c_str(),10*1024*1024);

writef(fullpath(writepath,"20M.s").c_str(),20*1024*1024);

//read

TimeDiff([&](){ readfile("128B.s"); },"assert 128 bytes time:%d");

TimeDiff([&](){ readfilea("128B.s"); },"Writable 128 bytes time:%d"); CCLOG("");

TimeDiff([&](){ readfile("512B.s"); },"assert 512 bytes time:%d");

TimeDiff([&](){ readfilea("512B.s"); },"Writable 512 bytes time:%d"); CCLOG("");

TimeDiff([&](){ readfile("2K.s"); },"assert 2k bytes time:%d");

TimeDiff([&](){ readfilea("2K.s"); },"Writable 2k bytes time:%d"); CCLOG("");

TimeDiff([&](){ readfile("4K.s"); },"assert 4k bytes time:%d");

TimeDiff([&](){ readfilea("4K.s"); },"Writable 4k bytes time:%d"); CCLOG("");

TimeDiff([&](){ readfile("16K.s"); },"assert 16k bytes time:%d");

TimeDiff([&](){ readfilea("16K.s"); },"Writable 16k bytes time:%d"); CCLOG("");

TimeDiff([&](){ readfile("512K.s"); },"assert 512K bytes time:%d");

TimeDiff([&](){ readfilea("512K.s"); },"Writable 512K bytes time:%d"); CCLOG("");

TimeDiff([&](){ readfile("1M.s"); },"assert 1M.s bytes time:%d");

TimeDiff([&](){ readfilea("1M.s"); },"Writable 1M.s time:%d"); CCLOG("");

TimeDiff([&](){ readfile("2M.s"); },"assert 2M.s bytes time:%d");

TimeDiff([&](){ readfilea("2M.s"); },"Writable 512K time:%d"); CCLOG("");

TimeDiff([&](){ readfile("5M.s"); },"assert 5M.s bytes time:%d");

TimeDiff([&](){ readfilea("5M.s"); },"Writable 5M.s time:%d"); CCLOG("");

TimeDiff([&](){ readfile("10M.s"); },"assert 10M.s bytes time:%d");

TimeDiff([&](){ readfilea("10M.s"); },"Writable 10M.s time:%d"); CCLOG("");

TimeDiff([&](){ readfile("20M.s"); },"assert 20M.s bytes time:%d");

TimeDiff([&](){ readfilea("20M.s"); },"Writable 20M.s time:%d"); CCLOG("");

}

}

结果对比:

assert 128 bytes time:1951

Writable 128 bytes time:544

assert 512 bytes time:939

Writable 512 bytes time:0

assert 2k bytes time:1153

Writable 2k bytes time:374

assert 4k bytes time:883

Writable 4k bytes time:0

assert 16k bytes time:1244

Writable 16k bytes time:0

assert 512K bytes time:3366

Writable 512K bytes time:1958

assert 1M.s bytes time:4856

Writable 1M.s time:2206

assert 2M.s bytes time:12929

Writable 512K time:4581

assert 5M.s bytes time:27459

Writable 5M.s time:20102

assert 10M.s bytes time:38956

Writable 10M.s time:24224

//=====================================

cocos2d 测试代码

//#ifdef s

////内存映射测试

//extern "C" {

//#include <time.h>

//#include <stdlib.h>

//#include <stdio.h>

//    void ptest(){

//        auto TimeDiff = [](std::function<void()> func,const char* msg){

//            clock_t t1 , t2;

//            t1 = clock();

//            func();

//            t2 = clock();

//            CCLOG(msg,t2-t1);

//        };

//

//        auto writef = [](const char* path,int len){

//            FILE* fp = fopen(path, "wr+");

//            unsigned char* c = (unsigned char*)malloc(len);

//            memset(c, 'T', len);

//            fwrite(c, 1, len, fp);

//            fflush(fp);

//            fclose(fp);

//            fp =nullptr;

//        };

//

//        auto readfile = [](const char* path){

//            std::string src("src/ptest/datas/");

//            src.append(path);

//            FileUtils::getInstance()->getStringFromFile(src);

//        };

//

//        auto readfilea = [](const char* path){

//            std::string src(FileUtils::getInstance()->getWritablePath());

//            src.append("/");

//            src.append(path);

//            FileUtils::getInstance()->getStringFromFile(src);

//        };

//

//

//        std::string writepath = FileUtils::getInstance()->getWritablePath();

//

//        auto fullpath = [](std::string path,const char* str){ path.append(str); return path; };

//

//        writef(fullpath(writepath,"128B.s").c_str(),128);

//        writef(fullpath(writepath,"512B.s").c_str(),512);

//        writef(fullpath(writepath,"2K.s").c_str(),2*1024);

//        writef(fullpath(writepath,"4K.s").c_str(),4*1024);

//        writef(fullpath(writepath,"16K.s").c_str(),16*1024);

//        writef(fullpath(writepath,"512K.s").c_str(),512*1024);

//        writef(fullpath(writepath,"1M.s").c_str(),1*1024*1024);

//        writef(fullpath(writepath,"2M.s").c_str(),2*1024*1024);

//        writef(fullpath(writepath,"5M.s").c_str(),5*1024*1024);

//        writef(fullpath(writepath,"10M.s").c_str(),10*1024*1024);

//        writef(fullpath(writepath,"20M.s").c_str(),20*1024*1024);

//

//        //read

//        TimeDiff([&](){ readfile("128B.s"); },"assert 128 bytes time:%d");

//        TimeDiff([&](){ readfilea("128B.s"); },"Writable 128 bytes time:%d"); CCLOG("");

//

//        TimeDiff([&](){ readfile("512B.s"); },"assert 512 bytes time:%d");

//        TimeDiff([&](){ readfilea("512B.s"); },"Writable 512 bytes time:%d"); CCLOG("");

//

//        TimeDiff([&](){ readfile("2K.s"); },"assert 2k bytes time:%d");

//        TimeDiff([&](){ readfilea("2K.s"); },"Writable 2k bytes time:%d"); CCLOG("");

//

//        TimeDiff([&](){ readfile("4K.s"); },"assert 4k bytes time:%d");

//        TimeDiff([&](){ readfilea("4K.s"); },"Writable 4k bytes time:%d"); CCLOG("");

//

//        TimeDiff([&](){ readfile("16K.s"); },"assert 16k bytes time:%d");

//        TimeDiff([&](){ readfilea("16K.s"); },"Writable 16k bytes time:%d"); CCLOG("");

//

//        TimeDiff([&](){ readfile("512K.s"); },"assert 512K bytes time:%d");

//        TimeDiff([&](){ readfilea("512K.s"); },"Writable 512K bytes time:%d"); CCLOG("");

//

//        TimeDiff([&](){ readfile("1M.s"); },"assert 1M.s bytes time:%d");

//        TimeDiff([&](){ readfilea("1M.s"); },"Writable 1M.s time:%d"); CCLOG("");

//

//        TimeDiff([&](){ readfile("2M.s"); },"assert 2M.s bytes time:%d");

//        TimeDiff([&](){ readfilea("2M.s"); },"Writable 2M.s time:%d"); CCLOG("");

//

//        TimeDiff([&](){ readfile("5M.s"); },"assert 5M.s bytes time:%d");

//        TimeDiff([&](){ readfilea("5M.s"); },"Writable 5M.s time:%d"); CCLOG("");

//

//        TimeDiff([&](){ readfile("10M.s"); },"assert 10M.s bytes time:%d");

//        TimeDiff([&](){ readfilea("10M.s"); },"Writable 10M.s time:%d"); CCLOG("");

//

//        TimeDiff([&](){ readfile("20M.s"); },"assert 20M.s bytes time:%d");

//        TimeDiff([&](){ readfilea("20M.s"); },"Writable 20M.s time:%d"); CCLOG("");

//

//    }

//}

//#endif

assert 20M.s bytes time:85986

Writable 20M.s time:50815

cocos2d 文件系统使用文件内存映射性能对比的更多相关文章

  1. 【JavaNIO的深入研究4】内存映射文件I/O,大文件读写操作,Java nio之MappedByteBuffer,高效文件/内存映射

    内存映射文件能让你创建和修改那些因为太大而无法放入内存的文件.有了内存映射文件,你就可以认为文件已经全部读进了内存,然后把它当成一个非常大的数组来访问.这种解决办法能大大简化修改文件的代码.fileC ...

  2. java大文件读写操作,java nio 之MappedByteBuffer,高效文件/内存映射

    java处理大文件,一般用BufferedReader,BufferedInputStream这类带缓冲的Io类,不过如果文件超大的话,更快的方式是采用MappedByteBuffer. Mapped ...

  3. .NET Framework自带的文件内存映射类

    最近一直为文件内存映射发愁,整个两周一直折腾这个东西.在64位系统和32位系统还要针对内存的高低位进行计算.好麻烦..还是没搞定 偶然从MSDN上发现.NET 4.0把内存文件映射加到了.NET类库中 ...

  4. MMAP文件内存映射

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  5. c++/MFC 封装好的文件内存映射类

    整理日: 2015年2月16日 首先介绍内存映射文件操作------函数的用法以及先后执行顺序 // 第一步:创建文件 HANDLE hFile = CreateFileForMapping(_T(& ...

  6. JMeter性能测试基础 (3) - 使用参数文件做搜索引擎性能对比

    本篇文章主要对如何在JMeter中进行URL的参数进行配置进行介绍,通过CSV文件配置参数数据,对baidu.sogou.haosou进行搜索性能对比测试. 1.建立测试计划.线程组,并在线程组下添加 ...

  7. 使用Java内存映射(Memory-Mapped Files)处理大文件

    >>NIO中的内存映射 (1)什么是内存映射文件内存映射文件,是由一个文件到一块内存的映射,可以理解为将一个文件映射到进程地址,然后可以通过操作内存来访问文件数据.说白了就是使用虚拟内存将 ...

  8. Java NIO内存映射---上G大文件处理(转)

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要讲了java中内存映射的原理及过程,与传统IO进行了对比,最后,用实例说明了结果 ...

  9. 《Java核心技术卷二》笔记(二)文件操作和内存映射文件

    文件操作 上一篇已经总结了流操作,其中也包括文件的读写.文件系统除了读写以为还有很多其他的操作,如复制.移动.删除.目录浏览.属性读写等.在Java7之前,一直使用File类用于文件的操作.Java7 ...

随机推荐

  1. HDFS集中化缓存管理

    概述 HDFS中的集中化缓存管理是一个明确的缓存机制,它允许用户指定要缓存的HDFS路径.NameNode会和保存着所需快数据的所有DataNode通信,并指导他们把块数据缓存在off-heap缓存中 ...

  2. cloudera manager 5.3完整卸载脚本

    service cloudera-scm-agent stop service cloudera-scm-agent stop umount /var/run/cloudera-scm-agent/p ...

  3. [01]url请求到渲染

    http状态码有哪些?分别表示什么意思?状态码告知从服务器返回的请求结果.2XX表明请求被正常处理了.200OK.204No Content(服务器接收的请求已经处理成功,但在返回的响应报文中不包含实 ...

  4. [06] JavaScript 类型

    下面对知识点总结: 1.类型分类 a.原始类型:number, string, boolean, null, undefined b.对象类型:除了原始类型都是(例如:object,array, fu ...

  5. bzoj4602 [Sdoi2016]齿轮

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4602 [题解] 对于每组齿轮(u, v)连边,权值为y/x(反向边x/y) 那么直接dfs计 ...

  6. 分布式缓存Memcache

    Memcached是分布式的,也就是说它不是本地的.它基于网络连接(当然它也可以使用localhost)方式完成服务,本身它是一个独立于应用的程序或守护进程(Daemon方式). Memcached使 ...

  7. 【洛谷 P3306】[SDOI2013]随机数生成器 (BSGS)

    题目链接 怎么这么多随机数生成器 题意见原题. 很容易想到\(BSGS\)算法,但是递推式是\(X_{i+1}=(aX_i+b)\mod p\),这显然不是一个等比数列. 但是可以用矩阵乘法来求出第\ ...

  8. 2017年上海金马五校程序设计竞赛:Problem I : Frog's Jumping (找规律)

    Description There are n lotus leaves floating like a ring on the lake, which are numbered 0, 1, ..., ...

  9. bzoj 1025 DP

    这道题根据群论的基础知识,我们可以转化成将n拆分成若干数,求这些数 的lcm的方案数 先筛下素数表prime 那么我们可以用DP来解决这个问题,用W[I,J]代表I这个数,拆成若干个数, 其中质因数最 ...

  10. C++11 lambda函数符

    #include<iostream> #include<vector> #include<algorithm> #include<cmath> #inc ...