当前位置: 首页 > news >正文

网站主播wordpress指定标签不同样式

网站主播,wordpress指定标签不同样式,免费观看高清正能量直播下载,网站建设管理属于职业资格吗不知道何时开始#xff0c;很多程序员喜欢用ToLower#xff0c;ToUpper去实现忽略大小写模式的字符串相等性比较#xff0c;有可能这个习惯是从别的语言引进的#xff0c;大胆猜测下是JS#xff0c;为了不引起争论#xff0c;我指的JS是技师的意思~一#xff1a;背景1. … 不知道何时开始很多程序员喜欢用ToLowerToUpper去实现忽略大小写模式的字符串相等性比较有可能这个习惯是从别的语言引进的大胆猜测下是JS为了不引起争论我指的JS是技师的意思~一背景1. 讲故事在我们一个订单聚合系统中每一笔订单都会标注来源比如JDTaobaoEtaoShopex 等等一些渠道UI上也提供高级配置输入自定义的订单来源后来客户反馈输入xxx查询不出订单这里就拿shopex为例用户用小写的shopex查询但系统中标注的是首字母大写的Shopex所以自然无法匹配为了解决这个问题开发小哥就统一转成大写做比对用代码表示如下var orderfrom shopex.ToUpper();customerIDList MemoryOrders.Where(i i.OrderFrom.ToUpper()orderFrom).Select(i i.CustomerId).ToList(); 改完后就是这么牛的上线了乍一看也没啥问题结果一查询明显感觉比之前速度慢了好几秒干脆多点几下好咯。。。在监控中发现CPU和memory突高突低异常波动这位小哥又在写bug了查了下代码问他为什么这么写小哥说在js中就是这么比较的~~~2. string.Compare 改造其实在C#中面对忽略大小写形式的比较是有专门的方法性能高而且还不费内存它就是 string.Compare所以把上面代码改成如下就可以了。var orderfrom shopex;customerIDList MemoryOrders.Where(string.Compare(i.TradeFrom, tradefrom,StringComparison.OrdinalIgnoreCase) 0).Select(i i.CustomerId).ToList(); 这其中的 StringComparison.OrdinalIgnoreCase枚举就是用来忽略大小写的上线之后除了CPU还是有点波动其他都没有问题了。二为什么ToLowerToUpper会有如此大的影响为了方便演示我找了一篇英文小短文然后通过查询某一个单词来演示ToUpper为啥对cpu和memory以及查询性能都有如此大的影响,代码如下public static void Main(string[] args){var strList Hooray! Its snowing! Its time to make a snowman.James runs out. He makes a big pile of snow. He puts a big snowball on top. He adds a scarf and a hat. He adds an orange for the nose. He adds coal for the eyes and buttons.In the evening, James opens the door. What does he see? The snowman is moving! James invites him in. The snowman has never been inside a house. He says hello to the cat. He plays with paper towels.A moment later, the snowman takes Jamess hand and goes out.They go up, up, up into the air! They are flying! What a wonderful night!The next morning, James jumps out of bed. He runs to the door.He wants to thank the snowman. But hes gone..Split( );var query snowman.ToUpper();for (int i 0; i strList.Length; i){var str strList[i].ToUpper();if (str query)Console.WriteLine(str);}Console.ReadLine();} 1. 内存波动探究既然内存有波动说明内存里进了脏东西学C#基础知识的时候应该知道string是不可变的一旦有修改就会生成新的string那就是说ToUpper之后会出现新的string为了用数据佐证用windbg演示一下。0:000 !dumpheap -type System.String -stat Statistics:MT Count TotalSize Class Name 00007ff8e7a9a120 1 24 System.Collections.Generic.GenericEqualityComparer1[[System.String, mscorlib]] 00007ff8e7a99e98 1 80 System.Collections.Generic.Dictionary2[[System.String, mscorlib],[System.Globalization.CultureData, mscorlib]] 00007ff8e7a9a378 1 96 System.Collections.Generic.Dictionary2Entry[[System.String, mscorlib],[System.Globalization.CultureData, mscorlib]][] 00007ff8e7a93200 19 2264 System.String[] 00007ff8e7a959c0 429 17894 System.String Total 451 object 可以看到托管堆上有Count429个string对象那这个429怎么来的组成短文128个ToUpper后128个系统默认165个query字符串2个,不明字符串6个最后就是128 128 165 2 6429然后随便抽几个看看。!dumpheap -mt 00007ff8e7a959c0 !DumpObj 000002244282a1f8 0:000 !DumpObj /d 0000017800008010 Name: System.String MethodTable: 00007ff8e7a959c0 EEClass: 00007ff8e7a72ec0 Size: 38(0x26) bytes File: C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll String: HOUSE. Fields:MT Field Offset Type VT Attr Value Name 00007ff8e7a985a0 4000281 8 System.Int32 1 instance 6 m_stringLength 00007ff8e7a96838 4000282 c System.Char 1 instance 48 m_firstChar 00007ff8e7a959c0 4000286 d8 System.String 0 shared static Empty Domain:Value 0000017878943bb0:NotInit 0:000 !DumpObj /d 0000017800008248 Name: System.String MethodTable: 00007ff8e7a959c0 EEClass: 00007ff8e7a72ec0 Size: 40(0x28) bytes File: C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll String: SNOWMAN Fields:MT Field Offset Type VT Attr Value Name 00007ff8e7a985a0 4000281 8 System.Int32 1 instance 7 m_stringLength 00007ff8e7a96838 4000282 c System.Char 1 instance 53 m_firstChar 00007ff8e7a959c0 4000286 d8 System.String 0 shared static Empty Domain:Value 0000017878943bb0:NotInit 查了两个全是大写的“HOUSE”“SNOWMAN”再回到我的场景有小百万订单也就会在托管堆上生成小百万个string如果再点一次又会生成小百万个内存怎么会不突增呢。。。2.cpu和查询时间探究现在大家知道了堆上可能有几百万个string对象这些对象的分配和释放给cpu造成了不小的压力本身toUpper之后速度变慢更惨的是还会造成gc颤抖式触发一颤抖所有的thread都会被暂停开启回收速度就更慢了。。。三string.Compare解析再回过头来看一下string.Compare为什么这么????????大家可以通过dnspy查看一下源码即可里面有一个核心函数如下图 // Token: 0x060004B8 RID: 1208 RVA: 0x00010C48 File Offset: 0x0000EE48[SecuritySafeCritical]private unsafe static int CompareOrdinalIgnoreCaseHelper(string strA, string strB){int num Math.Min(strA.Length, strB.Length);fixed (char* ptr strA.m_firstChar){fixed (char* ptr2 strB.m_firstChar){char* ptr3 ptr;char* ptr4 ptr2;while (num ! 0){int num2 (int)(*ptr3);int num3 (int)(*ptr4);if (num2 - 97 25){num2 - 32;}if (num3 - 97 25){num3 - 32;}if (num2 ! num3){return num2 - num3;}ptr3;ptr4;num--;}return strA.Length - strB.Length;}}} 这段代码很精妙巧妙的使用97将两个字符串按照大写模式的ascii码进行逐一比较相比在堆上搞一堆东西快捷的多。然后我修改一下代码看看此时堆上如何。。。public static void Main(string[] args){...var query snowman;for (int i 0; i strList.Length; i){if (string.Compare(strList[i], query, StringComparison.OrdinalIgnoreCase) 0){Console.WriteLine(strList[i]);}}Console.ReadLine();}0:000 !dumpheap -type System.String -stat Statistics:MT Count TotalSize Class Name 00007ff8e7a9a120 1 24 System.Collections.Generic.GenericEqualityComparer1[[System.String, mscorlib]] 00007ff8e7a99e98 1 80 System.Collections.Generic.Dictionary2[[System.String, mscorlib],[System.Globalization.CultureData, mscorlib]] 00007ff8e7a9a378 1 96 System.Collections.Generic.Dictionary2Entry[[System.String, mscorlib],[System.Globalization.CultureData, mscorlib]][] 00007ff8e7a93200 19 2264 System.String[] 00007ff8e7a959c0 300 13460 System.String Total 322 objects 从 System.String 中可以看到现在的堆上是300个而原来是429相当于少了129个也就是128个ToUpper加上1个Query中的ToUpper被消灭掉了。四总结平时我们哪些不好的写法在大量数据面前不堪一击同时也是一次好的成长机会~
http://www.pierceye.com/news/793855/

相关文章:

  • 找南昌网站开发公司电话寓意好的公司名字
  • 网站商城设计方案做网站的图片传进去很模糊
  • 百度站长平台电脑版cpm广告联盟平台
  • 哪些网站需要做分享按钮米卓网站建设
  • 做的网站怎样评估价值微商城网站建设平台
  • 后台网站更新 网站没显示广告投放代理商
  • 北京住房保障建设投资中心网站wordpress文章页面修改
  • 游戏网站建设项目规划书案例集约化网站群建设情况
  • 网站策划书编写阿里云部署多个网站
  • 品牌高端网站制作公司佛山新网站建设如何
  • 网站开发中怎么设置快捷键网页设计知名网站
  • 公司网上注册在哪个网站分析网络营销方式
  • 网站用什么颜色外贸企业建站公司
  • 网站下载音乐网站开发公司知乎
  • 什么样式表一般用于大型网站什么是seo搜索
  • 做网站用vue还是用jquery济宁网站建设 中企动力临沂
  • 网站专题教程最吸引人的营销广告词
  • 瑞安网站网站建设如何推广自己的店铺
  • 建设网站花都水泥公司网站建设
  • asp网站怎么下载源码农业做的好的网站
  • 导购网站怎么做视频教学网页设计与制作教程第5版
  • 建设部施工安全管理网站网站建设公司如何
  • 企业商城建站公司网站页面加密
  • 昆山教育云平台网站建设软件工程师考试报名
  • ps做网站大小尺寸大连开发区商场
  • 化妆品网站建设网站右键禁止
  • wordpress 没有样式表网站如何免费做SEO优化
  • 青岛有没有专门做淘宝网站中国建设人才网站
  • 网站移动端是什么问题吗怎样自己做免费的网站
  • 做网站没有做退钱宁波品牌策划公司