本项目的所有内容都拥有自主版权。
jemygraw / techdoc Goto Github PK
View Code? Open in Web Editor NEW自己编写的技术文档汇总
自己编写的技术文档汇总
Hi, jemygraw,
我有幸阅读了Go轻松学的iOS版本, 发现这是一本非常适合入门的golang学习教程. 但是由于只提供了android和iOS版本, 不便于在PC上进行学习.(例如: copy code, run, view run result etc). 因此我计划将《Go轻松学》利用gitbook制作电子版本, 不知道能否使用这个repository的markdown文档. gitbook当中将会保留你的版权信息. 并在制作好之后, release之前交由你review. 不知是否可行?
package main
import (
"fmt"
"time"
)
func get_sum_of_divisible(num int, divider int, resultChan chan int) {
sum := 0
for value := 0; value < num; value++ {
if value%divider == 0 {
sum += value
}
}
time.Sleep(time.Second * time.Duration((15 - divider)))
resultChan <- sum
}
func main() {
LIMIT := 1000
resultChan := make(chan int, 3)
t_start := time.Now()
go get_sum_of_divisible(LIMIT, 3, resultChan)
go get_sum_of_divisible(LIMIT, 5, resultChan)
go get_sum_of_divisible(LIMIT, 15, resultChan)
sum3, sum5, sum15 := <-resultChan, <-resultChan, <-resultChan
sum := sum3 + sum5 - sum15
t_end := time.Now()
fmt.Println(sum)
fmt.Println(t_end.Sub(t_start))
}
我加时间延时, time.Sleep(time.Second * time.Duration((15 - divider)))
假设这个函数执行的时间是不确定的,得到的结果就变成
sum = sum15 + sum5 - sum3
[root@localhost tutor-2]# go run par.go
-34168
12.000214639s
1000以内能被3或5整除的正整数和这个例子有误,我使用你代码,并去掉goroutine后输出233168,而你的原程序输出100498。且你也打印运行时间了,难道没发现运行时间没多大改变吗?因为你的代码只使用一个核,需要修改GOMAXPROCS参数,改后发现偶尔会输出不同的数。还是多channel省心。若以上有理解错误的,望能指出
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.