ToUpperInvariant使用不依赖于区域性进行转换,而ToUpper则使用了当前线程的CultureInfo,进行转换,所以性能会有所影响,以下为测试:

         [Test]
public void TestInvariant()
{
Int32 count = * ;
Stopwatch watch = new Stopwatch(); String str = "abcdefghijklmnopqrstuvwxyz中华人民共和国";
watch = Stopwatch.StartNew();
for (int i = ; i < count; i++)
{
str.ToUpperInvariant();
}
Console.WriteLine("ToUpperInvariant:{0}", watch.Elapsed.ToString());
} [Test]
public void TestNoInvariant()
{
Int32 count = * ;
Stopwatch watch = new Stopwatch(); String str = "abcdefghijklmnopqrstuvwxyz中华人民共和国";
watch = Stopwatch.StartNew();
for (int i = ; i < count; i++)
{
str.ToUpper();
}
Console.WriteLine("ToUpper:{0}", watch.Elapsed.ToString());
}

ToUpperInvariant:00:00:00.2980660

ToUpper:00:00:00.3281423

如果 确认当前的比较和区域性无关的话,推荐使用ToUppperInvariant

使用ToUpperInvariant避免使用ToUpper的更多相关文章

  1. C函数tolower,与toupper

    tolower    将大写转换成小写.  非字母字符不做出处理.   这个函数用法有点特殊他是处理字符的,而不是处理字符串的. 所谓的不能处理字符串不是说他不能处理字符串,他处理的时候对字符串必须是 ...

  2. 尽量使用ToUpper比较,避免使用ToLower

    在编码时尽量使用ToUpper比较,避免使用ToLower,因为微软对ToUpper进行了优化,以下为测试结果: public void TestToLower() { Stopwatch watch ...

  3. toupper函数及一些小程序

    toupper 原型:extern int toupper(int c); 用法:#include <ctype.h> 功能:将字符c转换为大写英文字母 说明:如果c为小写英文字母,则返回 ...

  4. (stringstream toupper 空格) 词组缩写 hdu2564

    词组缩写 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  5. 字符串转换atof atoi atol gcvt strtod strtol strto ul toascii tolower toupper

    atof(将字符串转换成浮点型数) 相关函数 atoi,atol,strtod,strtol,strtoul 表头文件 #include <stdlib.h> 定义函数 double at ...

  6. linu 把文件中的字母小写转换为大写,大写转换为小写awk toupper tolower

    cat aa.txt|tr "[a-z]" "A-Z" [root@ob2 mytmp]# awk '{print toupper($0)}' aa2.txt ...

  7. R语言改变大小写 toupper()和 tolower()函数

    这些函数改变字符串的字符的大小写. 语法 toupper()和 tolower()函数的基本语法为: toupper(x) tolower(x) 以下是所使用的参数的说明: x - 向量输入. 示例 ...

  8. About toupper()

    // toupper.c #include <stdio.h> #include <string.h> #include <ctype.h> int main() ...

  9. ccf 201409-3 字符串匹配(toupper,tolower)

     ccf 201409-3 字符串匹配(toupper,tolower) 问题描述 给出一个字符串和多行文字,在这些文字中找到字符串出现的那些行.你的程序还需支持大小写敏感选项:当选项打开时,表示同一 ...

随机推荐

  1. hdoj 2899 Strange fuction【二分求解方程】

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. hud 1241 dfs连同块

    Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground ...

  3. bzoj2657: [Zjoi2012]旅游(journey)

    求树的直径 真是太神辣 #include<cstdio> #include<cstring> #include<cstdlib> #include<algor ...

  4. Sencha Touch 和 jQuery Mobile 的比较

    Sencha Touch 和 jQuery Mobile 的比较 英文原文:Sencha Touch vs jQuery Mobile 标签: Sencha Touch jQuery Mobile 1 ...

  5. linux ptrace I

    这几天通过<游戏安全--手游安全技术入门这本书>了解到linux系统中ptrace()这个函数可以实现外挂功能,于是在ubuntu 16.04 x86_64系统上对这个函数进行了学习. 参 ...

  6. [转] CSS float 浮动属性

    http://www.cnblogs.com/polk6/p/3142187.html CSS float 浮动属性 本篇主要介绍float属性:定义元素朝哪个方向浮动. 目录: 1. 页面布局方式: ...

  7. 关于promise

    后来发现promise是解决异步的一个链式调用的好的方法,避免了所谓的回调的监狱, 它有三个状态,未作为,已经完成和已经失败,起始是未作为,然后有了动作总会有个结果, 分成resolve,已经顺利ok ...

  8. Weex 标签控件

    1.滚动组件 <template> <scroller> <div repeat="{{list}}"> <text>{{name} ...

  9. U3D 实现子弹发射效果

    首先,这里子弹要模拟的相似的话,用2D刚体比较好,会有重力,自由落体运动. using UnityEngine; using System.Collections; public class gun ...

  10. Adb工具常用操作-转(二)

    一. PC与模拟器或真机交换文件(adb pull和adb push) 在开发阶段或其他原因,经常需要将PC上的文件复制到模拟器或真机上,或将模拟机和真机上的文件复制到PC上.使用adb pull和a ...