zoukankan      html  css  js  c++  java
  • 获取exe所在目录路径,速度

    // test.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <Windows.h>
    #include <time.h>
    #include <string>
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        int size = 999999;
        TCHAR sCfgFile[MAX_PATH];
        DWORD dw_ret = GetModuleFileName(NULL, sCfgFile, MAX_PATH);
    
        time_t start, end ;   
        time(&start);  
     
        for (int i = 0; i < size; ++i)
        {
            std::wstring path = sCfgFile;
            if (0 != dw_ret)
            {
                size_t pos = path.find_last_of('\');
                if (-1 != pos)
                {
                    path = path.substr(0, pos + 1);
                }
            }
    
        }
    
        time(&end);  
        double cost=difftime(end,start);  
        //wprintf(L"转化成字符串后,获取路径话费时间----%f
    ",cost);  
        printf("转化成字符串后,获取路径话费时间----%f
    ",cost);  
    
        time_t start1, end1 ;   
        time(&start1);  
        int i = 0;
        for (int j = 0; j < size; ++j)
        {
            if (dw_ret > 0)
            {
                for (i = lstrlen(sCfgFile); sCfgFile[i] != '\' && i >0; i--);
    
                sCfgFile[i + 1] = '';
            }
    
        }
    
        time(&end1);  
        double cost1=difftime(end1,start1);  
        //wprintf(L"for循环找字符获取路径----%f
    ",cost1);  
        printf("for循环找字符获取路径----%f
    ",cost1);  
    
        time_t start2, end2 ;   
        time(&start2);  
    
        for (int i = 0; i < size; ++i)
        {
        }
    
        time(&end2);  
        double cost2=difftime(end2,start2);  
        printf("空循环----%f
    ",cost2); 
    
        system("pause");
    
        return 0;
    }

    这里是unicode编译环境

    如果是多字节编译的话,可以将 

    lstrlen(sCfgFile)换成strlen(sCfgFile),
    将sCfgFile的类型换成 char

    这里得到的结果是

    
    
  • 相关阅读:
    oracle 体系结构
    Oracle存储过程语法
    oracle 触发器
    oracle 存储过程
    oracle 高水位线详解
    oracle索引总结
    Oracle的表空间、数据文件、用户
    Oracle实例和数据库区别
    [whu1564]后缀数组
    [hdu4552]最长公共前缀
  • 原文地址:https://www.cnblogs.com/XiHua/p/5085051.html
Copyright © 2011-2022 走看看