小编Pin*_*juh的帖子

多次使用属性时的性能考虑因素

我在使用CultureInfo.CurrentCulture时形成我的字符串时使用string.format

引用此博客

这只是暗示如果您经常使用CurrentCulture,可能值得将其读入私有变量而不是大量调用CultureInfo.CurrentCulture,否则您将不必要地耗尽时钟周期.

所以这个作者

var culture = CultureInfo.CurrentCulture
string.Format(culture,"{0} some format string","some args");
string.Format(culture,"{0} some format string","some other args");
Run Code Online (Sandbox Code Playgroud)

比...更好

string.Format(CultureInfo.CurrentCulture,"{0} some format string","some args");
string.Format(CultureInfo.CurrentCulture,"{0} some format string","some other args");
Run Code Online (Sandbox Code Playgroud)

根据MSDN,CultureInfo.CurrentCulture是一个属性

多次访问属性时是否存在性能损失?

我还做了一些经验分析,我的测试表明,使用局部变量比直接使用属性更昂贵.

Stopwatch watch = new Stopwatch();

            int count = 100000000;
            watch.Start();
            for(int i=0;i<count;i++)
            {
                string.Format(CultureInfo.CurrentCulture, "{0} is my name", "ram");
            }


            watch.Stop();
                 //EDIT:Reset watch
                 watch.Reset();


            Console.WriteLine(watch.Elapsed);
            Console.WriteLine(watch.ElapsedMilliseconds);
            Console.WriteLine(watch.ElapsedTicks);


            Console.WriteLine("--------------------");
            var culture = CultureInfo.CurrentCulture;
            watch.Start();
            for (int i=0; i < count; i++)
            { …
Run Code Online (Sandbox Code Playgroud)

c# optimization performance properties

5
推荐指数
2
解决办法
449
查看次数

在ubuntu中卸载python模块

我必须删除一个名为"django"(一个流行的)的python模块,因为我安装了错误的版本(py-2.6中的1.3-beta).

如何卸载此模块?
请解释一下,因为我只在Windows中使用python而在Ubuntu中从不使用过python.

python django uninstall

5
推荐指数
1
解决办法
6121
查看次数

getchar和putchar

我的C代码:

int c;
c = getchar();

while (c != EOF) {
    putchar(c);
    c = getchar();
}
Run Code Online (Sandbox Code Playgroud)

为什么这个程序在输入方面会这样反应hello

hello
hello
Run Code Online (Sandbox Code Playgroud)

而不是像:

hheelloo
Run Code Online (Sandbox Code Playgroud)

c getchar

5
推荐指数
2
解决办法
2164
查看次数

开源公司如何避免有害贡献并找到有用的贡献?

因为维基百科是开源的,我可以修改任何我想要的东西.但如果有人删除,添加不良内容,修改有用内容会发生什么?维基百科为防止这种情况做了什么?

最后一个问题可用于任何其他开源软件:linux,php等.他们如何知道哪些贡献有用,哪些有害?谢谢.

open-source

4
推荐指数
1
解决办法
213
查看次数

Node JavaScript 上下文共享内置原型?

当创建与节点的一个新的上下文vm.runInNewContext,是内置的(ObjectFunction,等)原型共享或不?

上的文档runInNewContext说:

运行code无权访问本地范围,该对象sandbox将用作code.

是否Object.prototype在全局范围内,因此不共享?

node_script.cc:338-345node_script.cc:403-409我看到它正在引用对象,那么这些对象,来自sandbox,使用Object.prototype父上下文的 调用vm.runInNewContext和使用不同的在新上下文中创建的对象Object.prototype

(注意:vmmodule是迷宫:vmmodule -> evalsprocess.binding -> node_script.ccsource)

javascript v8 node.js

4
推荐指数
2
解决办法
819
查看次数

读取的字节数和无符号数

作为澄清我的问题的一个例子,在Google Go 1.0中,"io"包中定义了以下界面:

type Reader interface {
    Read(p []byte) (n int, err error)
}
Run Code Online (Sandbox Code Playgroud)

特别是结果参数列表(n int, err error)引起了我的兴趣.根据接口文档,本质上字节数不能为负数:

它返回读取的字节数(0 <= n <= len(p))[...]

在C中,使用的原因是用于表示错误条件int的带内值-1(请参阅有效转到:多个返回值).由于具有多个返回值,因此不需要特殊的带内值.

Go 1.0中存在类型uint.

在不使用特殊带内值的情况下,使用int相对于uint仅使用正范围[0,∞)的值的具体原因是什么?

io unsigned range go

4
推荐指数
1
解决办法
86
查看次数

ANTLR还是Regex?

我正在ASP.NET/C#中编写CMS,我需要处理每个页面请求这样的事情:

<html>
<head>
    <title>[Title]</title>
</head>
<body>
    <form action="[Action]" method="get">
        [TextBox Name="Email", Background=Red]
        [Button Type="Submit"]
    </form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

并当然更换[...]。

我的问题是我应该如何使用ANTLR或Regex来实现它?什么会更快?请注意,如果我要使用ANTLR来实现它,我认为我需要实现XML,作为[..]的附加内容。

我将需要实现参数,等等。

编辑:请注意,我的正则表达式甚至看起来像这样:

public override string ToString()
{
    return Regex.Replace(Input, @"\[
                                    \s*(?<name>\w+)\s*
                                    (?<parameter>
                                        [\s,]*
                                            (?<paramName>\w+)
                                            \s*
                                            =
                                            \s*
                                            (
                                                (?<paramValue>\w+)
                                                |
                                                (""(?<paramValue>[^""]*)"")
                                            )
                                    )*
                               \]", (match) =>
                                  {
                                      ...
                                  }, RegexOptions.IgnorePatternWhitespace);
}        
Run Code Online (Sandbox Code Playgroud)

.net c# regex performance antlr

3
推荐指数
1
解决办法
1481
查看次数

int foo(type&bar); 是一种不好的做法?

好吧,我们来了.我的C++书籍提出了另一个提议的做法.它说"返回值(非空)函数不应该将引用类型作为参数." 所以基本上如果你要实现这样的函数:

int read_file(int& into){
   ...
}
Run Code Online (Sandbox Code Playgroud)

并使用整数返回值作为某种错误指示符(忽略我们有异常的事实)然后该函数编写得很糟糕它实际上应该像

void read_file(int& into, int& error){

}
Run Code Online (Sandbox Code Playgroud)

现在对我来说,第一个更清晰,更好用.如果要忽略错误值,可以轻松完成.但是这本书暗示了后来的.请注意,本书并未说返回值函数是坏的.它宁愿说你应该只返回一个值,或者你应该只使用引用.

你对此有何看法?我的书上装满了废话吗?(再次)

c++ reference function

3
推荐指数
2
解决办法
404
查看次数

Erlang代码替换

我创建了一个简单的模块:

-module(check). 
-export([check/0]). 
check() ->
    Val = 1,
    io:format("Value = ~p~n",[Val]).
Run Code Online (Sandbox Code Playgroud)

编译的代码erlc.现在让我们运行Erlang:

Erlang R14B (erts-5.8.1) [source] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8.1  (abort with ^G)
1> check:check().
Value = 1
ok
Run Code Online (Sandbox Code Playgroud)

如果我修改代码,将Val更改为2,并使用erlc,我希望check:check将返回2,但事实并非如此:

2> check:check().
Value = 1
ok
Run Code Online (Sandbox Code Playgroud)

我们得到相同的结果.即使我重新启动shell.

如何在不杀死虚拟机的情况下强制Erlang重新加载模块?

compiler-construction erlang

3
推荐指数
1
解决办法
203
查看次数

(x86)汇编程序优化

我正在为Java构建针对Windows的x86-32(IA32)处理器的编译器/汇编器/链接器.

高级概念(我没有任何"源代码":没有语法或词汇翻译,所有语言都是常规的)被翻译成操作码,然后将其包装并输出到文件中.翻译过程有几个阶段,一个是常规语言之间的翻译:最高级别的代码被翻译成中级代码,然后被翻译成最低级别的代码(可能超过3个级别).

我的问题如下; 如果我有更高级别的代码(XY)转换为较低级代码(x,y,UV),那么这样的翻译的一个例子是,在伪代码:

x + U(f) // generated by X
+
V(f) + y // generated by Y
Run Code Online (Sandbox Code Playgroud)

(一个简单的例子)在哪里V是相反的U(与堆栈推送U和pop相比V).这需要"优化"为:

x + y
Run Code Online (Sandbox Code Playgroud)

(基本上删除"无用的"代码)

我的想法是使用正则表达式.对于上面的情况,它将是一个看起来像这样的正则表达式:x:(U(x)+V(x)):null,意思是所有x查找U(x)后跟V(x)和替换null.想象一下更复杂的正则表达式,用于更复杂的优化.这应该适用于所有级别.

你有什么建议?什么是优化和生产快速x86组件的好方法?

optimization assembly code-generation

2
推荐指数
2
解决办法
1818
查看次数