woaidongmao

文章均收录自他人博客,但不喜标题前加-[转贴],因其丑陋,见谅!~
随笔 - 1469, 文章 - 0, 评论 - 661, 引用 - 0
数据加载中……

CLogStr vs sprintf

测试规模:百万级别

在Debug模式下,CLogStr比sprintf大概慢1倍;

但是在Release模式下,CLogStr却快些。

log_str = "";与log_str.clear();效率差不多

 

// testLogString.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <Windows.h>
#include <__LSL_Cls_Define.h>
#include <__LogStr.h>

int main(int argc, char* argv[])
{
    int order = 978451;
    int login = 9;
    float volume = 2.0;
    double price = 145.1240;
    char* szSymbol = "EURUSD";
    char szBuf[256] = "";
    DWORD tick_beg = 0, tick_end = 0;
    __LSL_Cls::CLogStr log_str;
    int i = 0;

    tick_beg = GetTickCount();
    for(i = 0; i < 1000000; ++i)
        sprintf(szBuf, "#%d, %d buy %.2lf %s at price %.4lf successfully", order, login, volume, szSymbol, price);
    tick_end = GetTickCount();
    printf("sprintf total millseconds: %ld\r\n", tick_end - tick_beg);

    tick_beg = GetTickCount();
    for(i = 0; i < 1000000; ++i)
    {    log_str = "";//log_str.clear();
        log_str = log_str+"#"+order+", "+login+" buy "+volume+" "+szSymbol+" at price "+price+" successfully";
    //    printf("%s\n", log_str.c_str());
    //    Sleep(3000);
    }
    tick_end = GetTickCount();
    printf("log_str total millseconds: %ld\r\n", tick_end - tick_beg);
    return 0;
}

Debug模式下:

image

Release模式下:

image

posted on 2008-10-18 13:16 肥仔 阅读(271) 评论(0)  编辑 收藏 引用 所属分类: 其他经验


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理