正如我们从2010年的计算机语言基准游戏中看到的那样:
考虑到Go编译器生成用于执行的本机代码,这怎么可能呢?
Go的不成熟的编译器?或者Go语言存在一些内在问题?
编辑:
大多数答案否认Go语言的内在缓慢,声称问题存在于不成熟的编译器中.
因此,我已经做了一些自己的测试来计算Fibonacci数:迭代算法在Go(freebsd,6g)中运行,same
速度与C相同(使用O3选项).沉闷的递归运行在Go中2 times
比在C中慢(使用-O3选项;使用-O0 - 相同).但我没有看到基准游戏中的10倍跌幅.
如何在Go中访问命令行参数?它们不是作为参数传递的main
.
一个完整的程序,可能通过链接多个包创建,必须有一个名为main的包,带有一个函数
Run Code Online (Sandbox Code Playgroud)func main() { ... }
定义.函数main.main()不带参数,也不返回任何值.
我寻求一个perl模块将CppUnit输出转换为TAP格式.我想在之后使用prove命令来运行并检查测试.
任何原因导致这不能成为标准行为free()
?
多个指针指向同一个对象:
#include <stdlib.h>
#include <stdio.h>
void safefree(void*& p)
{
free(p); p = NULL;
}
int main()
{
int *p = (int *)malloc(sizeof(int));
*p = 1234;
int*& p2 = p;
printf("p=%p p2=%p\n", p, p2);
safefree((void*&)p2);
printf("p=%p p2=%p\n", p, p2);
safefree((void*&)p); // safe
return 0;
}
Run Code Online (Sandbox Code Playgroud)
来自malloc
要求的转让void*
反之亦然:
safefree()
要求转向void*&
(参考)
UNIX上的某些系统调用列表在哪里?
这不是我原来的问题,但无论如何,谢谢:)
下面的代码演示了这种差异:
#include <iostream>
#include <string>
int main()
{
char s[] = "ABCD";
std::string str(s);
char *p = s;
while(*p) {
*p++ = tolower(*p); // <-- incr after assignment
}
std::cout << s << std::endl;
std::string::iterator it = str.begin(), end = str.end();
while(it != end) {
*it++ = tolower(*it); // <-- incr before assignment ?
}
std::cout << str << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它产生输出:
abcd
bcd
Run Code Online (Sandbox Code Playgroud)
如果我们分配赋值操作和增量运算符:
while(it != end) {
*it = tolower(*it); // <-- incr before assignment ? …
Run Code Online (Sandbox Code Playgroud) 我正在使用Perl prove
测试实用程序(TAP :: Harness)来测试我的程序.
我需要先在本地计算机上运行相同的测试,然后再在远程计算机上运行.
(测试程序应分别连接到localhost或远程主机)
如何使用prove将参数(test_server)传递给测试?我应该使用环境还是有更好的解决方案?
从perldoc -f use
函数的语法use
:
use Module VERSION LIST
use Module VERSION
use Module LIST
use Module
use VERSION
Run Code Online (Sandbox Code Playgroud)
但在这种情况下:
use Test::More tests => 5;
Run Code Online (Sandbox Code Playgroud)
(它将测试次数设置为5)
表达的数据类型是tests => 5
什么?
是LIST还是其他什么?
tests
声明后如何使用此参数?
>> a = range(10)
>> print a[::-1]
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
Run Code Online (Sandbox Code Playgroud)
该切片给出了反向列表.它是如何工作的?
下面示例中的构造 ((..)) 的名称和语法是什么?
for ((i=1;i<10;i++)) do echo $i; done
Run Code Online (Sandbox Code Playgroud)
它有奇怪的变量 i ,
shell 中数字循环的其他结构在哪里?
perl ×3
bash ×2
c++ ×2
go ×2
testing ×2
unix ×2
benchmarking ×1
c ×1
cassandra ×1
command-line ×1
cppunit ×1
cycle ×1
free ×1
freebsd ×1
java ×1
junit ×1
memory-leaks ×1
parsing ×1
performance ×1
perl-prove ×1
python ×1
shell ×1
stl ×1
system-calls ×1