什么是'D'编程语言?人们开始用这种语言开发应用程序?谁找到了?我可以更多地了解这种新的编程语言吗?
Go和D广告宣传拥有令人难以置信的快速编译器.由于语言本身的现代设计,同时考虑了单通道解析.
了解大部分构建时间浪费在链接阶段.我想知道为什么gcc在小程序上仍然更快.
C
#include <stdio.h>
int main() {
printf("Hello\n");
}
Run Code Online (Sandbox Code Playgroud)
$ time gcc hello.c real 0m0.724s user 0m0.030s sys 0m0.046s
d
惯用的
import std.stdio;
void main() {
writeln("Hello\n");
}
Run Code Online (Sandbox Code Playgroud)
$ time dmd hello.d real 0m1.620s user 0m0.047s sys 0m0.015s
随着黑客
import core.stdc.stdio;
void main() {
printf("Hello\n");
}
Run Code Online (Sandbox Code Playgroud)
$ time dmd hello.d real 0m1.593s user 0m0.061s sys 0m0.000s $ time dmd -c hello.d real 0m1.203s user 0m0.030s sys 0m0.031s
走
package main
import "fmt"
func main() {
fmt.Println("Hello.")
}
Run Code Online (Sandbox Code Playgroud)
$ time …
我正在为自己的乐趣做基准测试!我已经用许多编程语言编写了一部分代码,并使用ab对其进行基准测试,以查看哪些更快,更多.我知道这个方法可能不那么有效,并且不能用作使用某些方法的明显方法,但对于我自己的信息,我这样做.我想知道的另一个因素是在每种语言中编写相同的样本是多么容易/困难.我用Python/Python(asyncio),Haskell,Go,Kotlin和D编写了代码.我将D端口设置为比Go更快(或者至少速度相等).但不幸的是我的D代码比Go慢得多.在这里我把oth代码,请帮助我为什么代码没有按预期快.或者我完全错了我的期望?
import cbor;
import std.array : appender;
import std.format;
import std.json;
import vibe.vibe;
struct Location
{
float latitude;
float longitude;
float altitude;
float bearing;
}
RedisClient redis;
void main()
{
auto settings = new HTTPServerSettings;
redis = connectRedis("localhost", 6379);
settings.port = 8080;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, &hello);
logInfo("Please open http://127.0.0.1:8080/ in your browser.");
runApplication();
}
void hello(HTTPServerRequest req, HTTPServerResponse res)
{
if (req.path == "/locations") {
immutable auto data = req.json;
immutable auto loc = deserializeJson!Location(data);
auto buffer = …Run Code Online (Sandbox Code Playgroud) 所以我正在为即将到来的算法编程竞赛练习,我偶然发现了前一年的问题.
我几乎解决了它(在C++中),但我得到了一些超时,所以我看了官方的解决方案,它是用Dlang编写的.
然后我试图模仿官方答案在D中做了什么,但我仍然得到超时(单次输入> 4秒).Afaik,C++应该比D更快,但是D在一瞬间解决了相同的输入,C++需要超过5秒的时间
这是D答案代码
import std.stdio;
import std.algorithm;
struct edge {
int src, des, w, o;
int opCmp (ref const edge e) const {
if(w != e.w) return w - e.w;
else return o - e.o;
}
};
const int MAXN = 100004, MAXM = 200004;
int N, M, D, ee, weight, days;
int[MAXN] ds;
edge[] edges;
void init() {
for(int i=1;i<=N;i++) ds[i] = i;
}
int find(int x) {
return ds[x] = (x == ds[x] ? x: find(ds[x])); …Run Code Online (Sandbox Code Playgroud)