自定义程序
1 subscriber
73 photos
15 videos
5 files
251 links
自定义程序丰富生活
Download Telegram
Forwarded from Rust 视界
【工具】vulkan-tutorial-rs 编程语言练习工具

#rust

[@timkofu](https://twitter.com/timkofu) 看完 The Book 后想找一个类似 [pythonchallenge.com](https://t.co/Q0vzcnTU9S) 网站,通过做一些编程练习学习 Rust,网友给他推荐了以下几个网站:

* [vulkan-tutorial-rs](https://github.com/bwasty/vulkan-tutorial-rs)
* [www.codewars.com](https://www.codewars.com/)
* [exercism.io](https://exercism.io)

刚学 Rust 不知道该做些什么项目的同学可以看看,顺便推荐[issuehub.com](http://issuehub.io),可以用“rust + help wanted”来搜索Rust 相关的开源项目,帮助开源项目解决issue也是一种练习方式。

[Read More](https://twitter.com/timkofu/status/1158415111394123776)
Forwarded from Rust 视界
十年Cpp程序员学了三个月Rust之后的感想

#cpp

文章不长,用作者的话来总结:与其把Rust看作是一门语言,倒不如将其看作是一个生态系统。他对Rust这个生态系统未来的成长感到非常excited。

- Facebook用Rust写区块链: Libra
- Goolge用Rust写操作系统: Fuchsia
- 亚马逊用Rust写虚拟化技术: FireCracker
- 微软推,崇业界都应该使用Rust语言。

看见了吗? 四大巨头的未来主要核心业务都交给或准备交给Rust了。

这也是这个10年Cpp程序员开始学习Rust的原因:未来。

Read More: [https://blog.aclysma.com/my-first-three-months-with-rust/](https://blog.aclysma.com/my-first-three-months-with-rust/)
Forwarded from Rust 视界
「SO问答」对超过240个元素的数组进行循环时,为什么会有很大的性能影响?

#stackoverflow

问题:

> 下面代码当 CAPACITY >= 240 的时候,与 CAPACITY >= 239 相比,性能慢了80倍。Rust编译器专门为240以内的长度做了优化? 使用 rustc -C opt-level=3 进行编译。

rust
use std::time::Instant;

const CAPACITY: usize = 240;
const IN_LOOPS: usize = 500000;

fn main() {
let mut arr = [0; CAPACITY];
for i in 0..CAPACITY {
arr[i] = i;
}
let mut sum = 0;
let now = Instant::now();
for _ in 0..IN_LOOPS {
let mut s = 0;
for i in 0..arr.len() {
s += arr[i];
}
sum += s;
}
println!("sum:{} time:{:?}", sum, now.elapsed());
}


解答:

> 总结:低于240,LLVM完全展开内部循环,可以优化掉重复循环,增加性能。

分析:

> 这是一个神奇的阈值,超过该阈值LLVM将停止执行某些优化。阈值是 8字节* 240 = 1920字节 (数组是usizes数组,因此长度乘以8字节,假设 x86-64 CPU)。在该问题中的基准测试中,是仅针对长度239执行的一个特定优化,所以导致了巨大的性能差异。

比如这段代码:

rust
pub fn foo() -> usize {
let arr = [0; 240];
let mut s = 0;
for i in 0..arr.len() {
s += arr[i];
}
s
}


你在 [godbolt](https://rust.godbolt.org/z/VKL9MS) 编辑器中查看生成的汇编代码,比较240和239,会发现有很大区别。比如当239的时候生成:

rust
movdqa xmm1, xmmword ptr [rsp + 32]
movdqa xmm0, xmmword ptr [rsp + 48]
paddq xmm1, xmmword ptr [rsp]
paddq xmm0, xmmword ptr [rsp + 16]
paddq xmm1, xmmword ptr [rsp + 64]
; more stuff omitted here ...
paddq xmm0, xmmword ptr [rsp + 1840]
paddq xmm1, xmmword ptr [rsp + 1856]
paddq xmm0, xmmword ptr [rsp + 1872]
paddq xmm0, xmm1
pshufd xmm1, xmm0, 78
paddq xmm1, xmm0


就是所谓的循环展开: LLVM将循环体粘贴一段时间,以避免执行那些“循环管理指令”,即循环变量的增量,检查循环是否结束和跳转。(可以自行对比一下240的输出)。但是,即便循环不展开,也不会造成80倍的性能差异。所以,实际上那个性能测试代码嵌套循环导致的(LLVM生成的代码基本上首先只执行内部循环(计算总和),然后通过多次累加总和来模拟外部循环!)。最好要使用Rust的惯用法: `arr.iter().sum()`,这样就不会产生80倍的性能差异了。

Read More: [https://stackoverflow.com/questions/57458460/why-is-there-a-large-performance-impact-when-looping-over-an-array-over-240-elem](https://stackoverflow.com/questions/57458460/why-is-there-a-large-performance-impact-when-looping-over-an-array-over-240-elem)
Forwarded from Rust 视界
Crev的使用教程

#Crev

[cargo-crev](https://github.com/dpc/crev/tree/master/cargo-crev)是一个代码审查工具,旨在构建信任的生态网络。但它并不局限于Rust社区,C/Cpp也可以使用。

该工具可以判断你项目中依赖crate的安全性、质量和发现的问题。可以在公共的git仓库里发布可验证的review信息。通过这种方式期望在Rust生态系统中构建可信任的网络。将不会有人再受到未经审查和不受信任代码的困扰。

想想npm因为依赖包出了多少次安全事故。这个工具ms不错,但是否真的可以解决问题?

Read More: [https://wiki.alopex.li/ActuallyUsingCrev](https://wiki.alopex.li/ActuallyUsingCrev)
Forwarded from Rust 视界
使用Rust进行游戏开发6个月之后收获到了什么?

#game

一位使用Rust开发游戏的妹纸,最近6个月内使用ggez框架开发自己的个人游戏项目,这篇文章简单介绍了她的一些感想,比如如何坚持做自己的项目、ECS很棒之类的。

重点是她之前写的另一篇文章:24小时游戏开发,介绍了如何使用ggez框架在24小时内开发一款小游戏。感兴趣的看看吧。

Read More: [https://iolivia.me/posts/6-months-of-rust-game-dev/](https://iolivia.me/posts/6-months-of-rust-game-dev/)
Forwarded from Rust 视界
「思考」对于小的结构体,传值(By-Copy)还是传引用(By-Borrow)?

#Struct

这个小小的问题,涉及日常编写代码需要考虑的两个问题:性能 vs 人体工程学

我们是追求性能呢,还是追求代码的可读性和维护性等?

该文作者通过大篇幅的讨论,甚至深入到C++中探讨,得出结论:还是By-Copy吧。至于原因,还需要仔细阅读他的文章。

Read More: [https://www.forrestthewoods.com/blog/should-small-rust-structs-be-passed-by-copy-or-by-borrow/](https://www.forrestthewoods.com/blog/should-small-rust-structs-be-passed-by-copy-or-by-borrow/)
Forwarded from Rust 视界
sn0int - 半自动化 OSINT 框架和包管理器

OSINT 就是“公开资源情报”,常见于安全和黑客领域。这个 sn0int 是给 IT 安全专业人士和 bug 捕获者设计的 OSINT 框架及包管理器。它用于对给定的目标或你自己搜集情报,生成统一的格式,给后续的研究使用。

Rust 已经悄悄占领安全/黑客领域了。[https://sn0int.readthedocs.io/en/stable/](https://sn0int.readthedocs.io/en/stable/)

Repo: [https://github.com/kpcyrd/sn0int](https://github.com/kpcyrd/sn0int)
Forwarded from .
SSTAP 完美替代品,V2ray 转 VPN 工具,可以用来加密 IP 连接 Xshell 避免暴露自己 IP,实在太好用了吼吼吼。
Forwarded from Improve Your English🌙
USEFUL IELTS INTERVIEW EXPRESSIONS

1️⃣ Saying something in another way

🔸What I'm trying to say is...

🔸In other words...

🔸To put it another way...

🔸What I mean is...

🔸Perhaps I should make that clearer by saying...

2️⃣ Agreeing with an opinion

🔸Yes, I agree...

🔸That's my view exactly.

🔸I would tend to agree with that.

🔸I couldn't agree more.

3️⃣ Disagreeing with an opinion

🔸No, I disagree.

🔸I'm afraid I disagree.

🔸I see things rather differently myself.

🔸I wouldn't say that is necessarily true.

🔸I tend to disagree.

🔸I'm not so sure about that.

4️⃣ Partially agreeing with an opinion

🔸I don't entirely agree. It is true that......however...

🔸That is partly true, but...

🔸I agree with that to an extent. However...

5️⃣ Getting asked an opinion (by the examiner)

🔸What do you think?

🔸What's your view / opinion?

🔸What are your views on...?

🔸How do you feel about...?

6️⃣ Saying your opinion could vary according to the situation

🔸That depends...

🔸I think it really depends...

🔸That depends on how you look at it.

7️⃣ Asking for clarification (part 3 only)

🔸Could you please explain what ...(word)... means?

🔸Sorry, I don't understand the question. Could you explain?

🔸Sorry, I'm afraid I didn't understand the question.

🔸Sorry, can I just clarify what you mean. Are you asking me ...(say what you believe you have been asked)...

8️⃣ Asking for repetition

🔸Sorry, would you mind repeating the question?

🔸Sorry, I didn't quite catch that. Could you repeat the question?


9️⃣ Summing up

🔸So all in all...

🔸To sum up...

🔸To conclude...
Forwarded from .
https://www.blog.duomly.com/how-to-start-with-machine-learning/
在这个人人都在谈论人工智能,传播大量无头绪机器学习资源资料的年代,初学者到底如何开始学习?本文作者给出了建议。