主頁 > 區塊鏈 > golang筆記09--go語言測驗與性能調優

golang筆記09--go語言測驗與性能調優

2021-02-18 11:09:48 區塊鏈

golang筆記09--go語言測驗與性能調優

  • 1 介紹
  • 2 測驗與性能調優
    • 2.1 測驗介紹
    • 2.2 代碼覆寫率和性能測驗
    • 2.3 使用pprof進行性能調優
    • 2.4 測驗http服務器(上)
    • 2.5 測驗http服務器(下)
    • 2.6 生成檔案和示例代碼
  • 3 注意事項
  • 4 說明

1 介紹

本文繼上文 golang筆記08–go語言錯誤處理和資源管理, 進一步了解 go語言的錯誤處理和資源管理,以及相應注意事項,
具體包括 : 測驗介紹 、代碼覆寫率和性能測驗、使用pprof進行性能調優、p測驗http服務器(上)、測驗http服務器(下)、生成檔案和示例代碼 等內容,

2 測驗與性能調優

2.1 測驗介紹

傳統測驗 vs 表格測驗:

傳統測驗表格測驗
測驗資料和測驗邏輯混在一起分離的測驗資料和測驗邏輯
出錯資訊不明確明確的出錯資訊
一旦一個資料出錯測驗全部結束可以部分失敗

兩者測驗代碼結構如下圖所示(左邊傳統、右邊表格):
在這里插入圖片描述

vim triangle.go
package main

import (
	"fmt"
	"math"
)

func triangle() {
	var a, b int = 3, 4
	c := calTriangle(a, b)
	fmt.Println(c)
}

func calTriangle(a, b int) int {
	var c int
	c = int(math.Sqrt(float64(a*a + b*b)))
	return c
}

vim triangle_test.go
package main

import "testing"

func TestTriangle(t *testing.T) {
	tests := []struct{ a, b, c int }{
		{3, 4, 5},
		{5, 12, 13},
		{8, 15, 17},
		{12, 35, 37},
		{3000, 4000, 5000},
		//{3000, 4000, 5001},
	}
	for _, tt := range tests {
		if actual := calTriangle(tt.a, tt.b); actual != tt.c {
			t.Errorf("calTriangle(%d, %d); got %d; expected %d", tt.a, tt.b, tt.c, calTriangle(tt.a, tt.b))
		}
	}
}
輸出:
=== RUN   TestTriangle
--- PASS: TestTriangle (0.00s)
PASS
出錯輸出:
=== RUN   TestTriangle
    triangle_test.go:16: calTriangle(3000, 4000); got 5001; expected 5000
--- FAIL: TestTriangle (0.00s)
FAIL

2.2 代碼覆寫率和性能測驗

IDEA 中,對于testing型別的程式,可以直接通過查看 Run TestTriangle in lear… with Coverage來查看測驗代碼的覆寫率(也可以根據需要選擇CPU 或者 Memory Profiler),如下圖所示:
在這里插入圖片描述
在這里插入圖片描述

vim triangle.go
package main

import (
	"fmt"
	"math"
)

func triangle() {
	var a, b int = 3, 4
	c := calTriangle(a, b)
	fmt.Println(c)
}

func calTriangle(a, b int) int {
	var c int
	c = int(math.Sqrt(float64(a*a + b*b)))
	return c
}

vim triangle_test.go
package main

import "testing"

func TestTriangle(t *testing.T) {
	tests := []struct{ a, b, c int }{
		{3, 4, 5},
		{5, 12, 13},
		{8, 15, 17},
		{12, 35, 37},
		{3000, 4000, 5000},
		//{3000, 4000, 5001},
	}
	for _, tt := range tests {
		if actual := calTriangle(tt.a, tt.b); actual != tt.c {
			t.Errorf("calTriangle(%d, %d); got %d; expected %d", tt.a, tt.b, tt.c, calTriangle(tt.a, tt.b))
		}
	}
}

func BenchmarkTriangle(b *testing.B) {
	a1, b1, c1 := 30000, 40000, 50000
	for i := 0; i < b.N; i++ {
		actual := calTriangle(a1, b1)
		if actual != c1 {
			b.Errorf("calTriangle(%d, %d); got %d; expected %d", a1, b1, c1, calTriangle(a1, b1))
		}
	}
}

TestTriangle 輸出:
=== RUN   TestTriangle
--- PASS: TestTriangle (0.00s)
PASS

BenchmarkTriangle 輸出:
goos: linux
goarch: amd64
pkg: learngo/chapter9/9.1
BenchmarkTriangle
BenchmarkTriangle-4   	1000000000	         0.285 ns/op 【執行了1000000000此操作,平均每次操作0.285 ns】
PASS

除了上述 ide直接執行測驗用例外,也可以通過命令列執行測驗用例:
1) 在測驗用例當前目錄執行go test就可以執行測驗用例
chapter9/9.1$ go test
2)通過 coverprofile=c.out 可以輸出測驗覆寫率到 c.out 檔案
chapter9/9.1$ go test -coverprofile=c.out
PASS
coverage: 50.0% of statements
ok      learngo/chapter9/9.1    0.002s
可以進一步通過 chapter9/9.1$ go tool cover -html c.out 查看覆寫率資訊
3)命令列執行benchmark
go test -bench .

2.3 使用pprof進行性能調優

本案例使用benchmark 的 cpuprofile,結合尋找最長不重復子串來逐步優化程式性能,案例中的 web 圖示需要依賴 graphviz ,

具體思路: -cpuprofile獲取性能資料 --》go tool pprof查看性能資料 --》根據web圖分析慢在哪里 --》優化代碼

vim 9.2.go
package main

import "fmt"

func lengthOfNonRepeatSubStrOld(s string) int {
	lastOccurred := make(map[rune]int)
	start := 0
	maxLength := 0
	for i, ch := range []rune(s) {
		if lastI, ok := lastOccurred[ch]; ok && lastI >= start {
			start = lastI + 1
		}
		if i-start+1 > maxLength {
			maxLength = i - start + 1
		}
		lastOccurred[ch] = i
	}
	return maxLength
}

var lastOccurred = make([]int, 0xffff) //假定中文字的最大值為65535=0xffff
func lengthOfNonRepeatSubStr(s string) int {
	// lastOccurred := make([]int, 0xffff) //假定中文字的最大值為65535=0xffff
	for i := range lastOccurred {
		lastOccurred[i] = -1
	}
	start := 0
	maxLength := 0
	for i, ch := range []rune(s) {
		if lastI := lastOccurred[ch]; lastI != -1 && lastI >= start {
			start = lastI + 1
		}
		if i-start+1 > maxLength {
			maxLength = i - start + 1
		}
		lastOccurred[ch] = i
	}
	return maxLength
}

func main() {
	fmt.Println("this chapter 9.3")
	str := "黑化肥揮發發灰會花飛灰化肥揮發發黑會飛花"
	fmt.Printf("%s lengthOfNonRepeatSubStr = %d ", str, lengthOfNonRepeatSubStr(str))
}

vim nonrepeating_test.go
package main

import "testing"

func BenchmarkSubstr(b *testing.B) {
	s := "黑化肥揮發發灰會花飛灰化肥揮發發黑會飛花"
	for i := 0; i < 13; i++ {
		s = s + s
	}
	b.Logf("len(s) = %d", len(s))
	ans := 8
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		actual := lengthOfNonRepeatSubStr(s)
		if actual != ans {
			b.Errorf("got %d for input %s; "+"expected %d", actual, s, ans)
		}
	}
}

輸出(沒有優化):
$ go test -bench . -cpuprofile cpu.out
goos: linux
goarch: amd64
pkg: learngo/chapter9/9.2
BenchmarkSubstr-4            178           6580817 ns/op
--- BENCH: BenchmarkSubstr-4
    nonrepeating_test.go:10: len(s) = 491520
    nonrepeating_test.go:10: len(s) = 491520
    nonrepeating_test.go:10: len(s) = 491520
PASS
ok      learngo/chapter9/9.2    2.016s
輸出(優化rune字串功能):
goos: linux
goarch: amd64
pkg: learngo/chapter9/9.2
BenchmarkSubstr-4            426           2756128 ns/op
--- BENCH: BenchmarkSubstr-4
    nonrepeating_test.go:10: len(s) = 491520
    nonrepeating_test.go:10: len(s) = 491520
    nonrepeating_test.go:10: len(s) = 491520
PASS
ok      learngo/chapter9/9.2    1.612s
輸出(將make 放在最外層):
goos: linux
goarch: amd64
pkg: learngo/chapter9/9.2
BenchmarkSubstr-4            486           2332484 ns/op
--- BENCH: BenchmarkSubstr-4
    nonrepeating_test.go:10: len(s) = 491520
    nonrepeating_test.go:10: len(s) = 491520
    nonrepeating_test.go:10: len(s) = 491520
PASS
ok      learngo/chapter9/9.2    1.511s

也可以通過命令列來測驗cpu性能:
go test -bench . -cpuprofile cpu.out
可以通過tool進一步查看cpu.out 資訊,  go tool pprof cpu.out ->互動終端輸出 web就會顯示出測驗時間關系圖,結果如下(需要安裝graphviz)

在這里插入圖片描述
從圖中可以看到 2 個map 和 一個rune 發的時間較多,rune 暫時不適合優化,但是 map 可以適當優化為對應的陣列
在這里插入圖片描述
優化后的耗時圖如下,課件優化后主要時間發在 stringtoslicerune 上了,當然還有少量時間發在 makeslice 上面(0.05s):
在這里插入圖片描述
進一步將make 移到函式外面,可以發現壓測時間進一步略微減少了,此時結果中以及沒有 makeslice 了:
在這里插入圖片描述

2.4 測驗http服務器(上)

本案例基于 golang筆記08–go語言錯誤處理和資源管理 中的 filelisting 來測驗 http 服務,具體示例如下:

chapter8/8.3$ tree -L 2
.
├── filelisting
│   └── handler.go
├── web.go
└── web_test.go

vim web_test.go
package main

import (
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"
)

func errPanic(_ http.ResponseWriter,
	_ *http.Request) error {
	panic(123)
}

var tests = []struct {
	h       appHandler
	code    int
	message string
}{
	{errPanic, 500, "Internal Server Error"},
}

func TestErrWarpper(t *testing.T) {
	for _, tt := range tests {
		f := errWarpper(tt.h)
		response := httptest.NewRecorder()
		request := httptest.NewRequest(http.MethodGet, "http://www.imooc.com", nil)
		f(response, request)
		b, _ := ioutil.ReadAll(response.Body)
		body := strings.Trim(string(b), "\n") // web默認回傳有個換行符,此處需要去掉才能正確匹配
		if response.Code != tt.code || body != tt.message {
			t.Errorf("expect (%d, %s); got (%d, %s)", tt.code, tt.message, response.Code, body)
		}
	}
}
輸出:
=== RUN   TestErrWarpper
--- PASS: TestErrWarpper (0.00s)
PASS

2.5 測驗http服務器(下)

http 測驗通常包括兩種方式:
1) 通過使用假的Request/Response
2)通過起服務器

本案例對上述 2.4 中的測驗 case 進一步豐富, 使之能夠測驗更多例外情況,具體內容如下:

vim web2_test.go
package main

import (
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"os"
	"strings"
	"testing"
)

func errPanic2(_ http.ResponseWriter,
	_ *http.Request) error {
	panic(123)
}

type testingUserError string

func (e testingUserError) Error() string {
	return e.Message()
}

func (e testingUserError) Message() string {
	return string(e)
}

func errUserError(_ http.ResponseWriter,
	_ *http.Request) error {
	return testingUserError("user error")
}

func errNotFound(_ http.ResponseWriter,
	_ *http.Request) error {
	return os.ErrNotExist
}

func errNoPermission(_ http.ResponseWriter,
	_ *http.Request) error {
	return os.ErrPermission
}

func errUnknown(_ http.ResponseWriter,
	_ *http.Request) error {
	return errors.New("unknown error")
}

func noError(writer http.ResponseWriter,
	_ *http.Request) error {
	fmt.Fprintln(writer, "no error")
	return nil
}

var tests = []struct {
	h       appHandler
	code    int
	message string
}{
	{errPanic2, 500, "Internal Server Error"},
	{errUserError, 400, "user error"},
	{errNotFound, 404, "Not Found"},
	{errNoPermission, 403, "Forbidden"},
	{errUnknown, 500, "Internal Server Error"},
	{noError, 200, "no error"},
}

func TestErrWarpper2(t *testing.T) {
	for _, tt := range tests {
		f := errWarpper(tt.h)
		response := httptest.NewRecorder()
		request := httptest.NewRequest(http.MethodGet, "http://www.imooc.com", nil)
		f(response, request)
		b, _ := ioutil.ReadAll(response.Body)
		body := strings.Trim(string(b), "\n") // web默認回傳有個換行符,此處需要去掉才能正確匹配
		if response.Code != tt.code || body != tt.message {
			t.Errorf("expect (%d, %s); got (%d, %s)", tt.code, tt.message, response.Code, body)
		}
	}
}

func TestErrWarpperInserver(t *testing.T) {
	for _, tt := range tests {
		f := errWarpper(tt.h)
		server := httptest.NewServer(http.HandlerFunc(f))
		resp, _ := http.Get(server.URL)
		b, _ := ioutil.ReadAll(resp.Body)
		body := strings.Trim(string(b), "\n") // web默認回傳有個換行符,此處需要去掉才能正確匹配
		if resp.StatusCode != tt.code || body != tt.message {
			t.Errorf("expect (%d, %s); got (%d, %s)", tt.code, tt.message, resp.StatusCode, body)
		}
	}
}
輸出(TestErrWarpper2)=== RUN   TestErrWarpper2
gopm WARN error occurred handling request: user error
gopm WARN error occurred handling request: file does not exist
gopm WARN error occurred handling request: permission denied
gopm WARN error occurred handling request: unknown error
--- PASS: TestErrWarpper2 (0.00s)
PASS
輸出(TestErrWarpperInserver)=== RUN   TestErrWarpperInserver
gopm WARN error occurred handling request: user error
gopm WARN error occurred handling request: file does not exist
gopm WARN error occurred handling request: permission denied
gopm WARN error occurred handling request: unknown error
--- PASS: TestErrWarpperInserver (0.00s)
PASS

2.6 生成檔案和示例代碼

go語言中可以通過go doc 查看代碼的包和對應的函式,也可以查看系統檔案功能,

1) 通過 go doc 查看queue 的檔案資訊
chapter6/queue$ go doc
package queue // import "learngo/chapter6/queue"

type Queue []interface{}

2)通過 go doc 查看具體資料結構資訊
chapter6/queue$ go doc Queue
go doc Queue
package queue // import "."

type Queue []interface{}

func (q *Queue) IsEmpty() bool
func (q *Queue) Pop() interface{}
func (q *Queue) Push(v interface{})

3) 查看go庫函式說明檔案 
$ go doc fmt.println

4)輸出godoc 的 http 服務器
$ godoc -http :6060
若在專案目錄下起,則會包括專案的檔案資訊

5) 若需要添加檔案,則直接將注釋卸載函式上一或行即可,例如
// this is push interface
func (q *Queue) Push(v interface{}) {
	*q = append(*q, v)
}

6) go 中也可以新建Example示例代碼,并能檢查相關的結果,如果生成對應的godoc,則會生成對應的 Example的 Code 和 Output,具體代碼如下
func ExampleQueue_Pop() {
	q := Queue{1}
	q.Push(2)
	q.Push(3)
	fmt.Println(q.Pop())
	fmt.Println(q.Pop())
	fmt.Println(q.IsEmpty())

	fmt.Println(q.Pop())
	fmt.Println(q.IsEmpty())

	// Output:
	// 1
	// 2
	// false
	// 3
	// true
}

通過本地 godoc 起一個檔案查詢服務器:
在這里插入圖片描述

3 注意事項

  1. 查看 cpuprofile 資訊時需要安裝 graphviz
    apt install graphviz
    

4 說明

  1. 軟體環境
    go版本:go1.15.8
    作業系統:Ubuntu 20.04 Desktop
    Idea:2020.01.04
  2. 參考檔案
    由淺入深掌握Go語言 --慕課網
    go 語言編程 --許式偉
    graphviz download

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/260645.html

標籤:區塊鏈

上一篇:Solidity進階之路:搭建僵尸工廠 - 第1章: 課程概述

下一篇:第一節 Go的安裝與應用

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • JAVA使用 web3j 進行token轉賬

    最近新學習了下區塊鏈這方面的知識,所學不多,給大家分享下。 # 1. 關于web3j web3j是一個高度模塊化,反應性,型別安全的Java和Android庫,用于與智能合約配合并與以太坊網路上的客戶端(節點)集成。 # 2. 準備作業 jdk版本1.8 引入maven <dependency> < ......

    uj5u.com 2020-09-10 03:03:06 more
  • 以太坊智能合約開發框架Truffle

    前言 部署智能合約有多種方式,命令列的瀏覽器的渠道都有,但往往跟我們程式員的風格不太相符,因為我們習慣了在IDE里寫了代碼然后打包運行看效果。 雖然現在IDE中已經存在了Solidity插件,可以撰寫智能合約,但是部署智能合約卻要另走他路,沒辦法進行一個快捷的部署與測驗。 如果團隊管理的區塊節點多、 ......

    uj5u.com 2020-09-10 03:03:12 more
  • 谷歌二次驗證碼成為區塊鏈專用安全碼,你怎么看?

    前言 谷歌身份驗證器,前些年大家都比較陌生,但隨著國內互聯網安全的加強,它越來越多地出現在大家的視野中。 比較廣泛接觸的人群是國際3A游戲愛好者,游戲盜號現象嚴重+國外賬號安全應用廣泛,這類游戲一般都會要求用戶系結名為“兩步驗證”、“雙重驗證”等,平臺一般都推薦用谷歌身份驗證器。 后來區塊鏈業務風靡 ......

    uj5u.com 2020-09-10 03:03:17 more
  • 密碼學DAY1

    目錄 ##1.1 密碼學基本概念 密碼在我們的生活中有著重要的作用,那么密碼究竟來自何方,為何會產生呢? 密碼學是網路安全、資訊安全、區塊鏈等產品的基礎,常見的非對稱加密、對稱加密、散列函式等,都屬于密碼學范疇。 密碼學有數千年的歷史,從最開始的替換法到如今的非對稱加密演算法,經歷了古典密碼學,近代密 ......

    uj5u.com 2020-09-10 03:03:50 more
  • 密碼學DAY1_02

    目錄 ##1.1 ASCII編碼 ASCII(American Standard Code for Information Interchange,美國資訊交換標準代碼)是基于拉丁字母的一套電腦編碼系統,主要用于顯示現代英語和其他西歐語言。它是現今最通用的單位元組編碼系統,并等同于國際標準ISO/IE ......

    uj5u.com 2020-09-10 03:04:50 more
  • 密碼學DAY2

    ##1.1 加密模式 加密模式:https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html ECB ECB : Electronic codebook, 電子密碼本. 需要加密的訊息按照塊密碼的塊大小被分為數個塊,并對每個塊進 ......

    uj5u.com 2020-09-10 03:05:42 more
  • NTP時鐘服務器的特點(京準電子)

    NTP時鐘服務器的特點(京準電子) NTP時鐘服務器的特點(京準電子) 京準電子官V——ahjzsz 首先對時間同步進行了背景介紹,然后討論了不同的時間同步網路技術,最后指出了建立全球或區域時間同步網存在的問題。 一、概 述 在通信領域,“同步”概念是指頻率的同步,即網路各個節點的時鐘頻率和相位同步 ......

    uj5u.com 2020-09-10 03:05:47 more
  • 標準化考場時鐘同步系統推進智能化校園建設

    標準化考場時鐘同步系統推進智能化校園建設 標準化考場時鐘同步系統推進智能化校園建設 安徽京準電子科技官微——ahjzsz 一、背景概述隨著教育事業的快速發展,學校建設如雨后春筍,隨之而來的學校教育、管理、安全方面的問題成了學校管理人員面臨的最大的挑戰,這些問題同時也是學生家長所擔心的。為了讓學生有更 ......

    uj5u.com 2020-09-10 03:05:51 more
  • 位元幣入門

    引言 位元幣基本結構 位元幣基礎知識 1)哈希演算法 2)非對稱加密技術 3)數字簽名 4)MerkleTree 5)哪有位元幣,有的是UTXO 6)位元幣挖礦與共識 7)區塊驗證(共識) 總結 引言 上一篇我們已經知道了什么是區塊鏈,此篇說一下區塊鏈的第一個應用——位元幣。其實先有位元幣,后有的區塊 ......

    uj5u.com 2020-09-10 03:06:15 more
  • 北斗對時服務器(北斗對時設備)電力系統應用

    北斗對時服務器(北斗對時設備)電力系統應用 北斗對時服務器(北斗對時設備)電力系統應用 京準電子科技官微(ahjzsz) 中國北斗衛星導航系統(英文名稱:BeiDou Navigation Satellite System,簡稱BDS),因為是目前世界范圍內唯一可以大面積提供免費定位服務的系統,所以 ......

    uj5u.com 2020-09-10 03:06:20 more
最新发布
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:46:47 more
  • Hyperledger Fabric 使用 CouchDB 和復雜智能合約開發

    在上個實驗中,我們已經實作了簡單智能合約實作及客戶端開發,但該實驗中智能合約只有基礎的增刪改查功能,且其中的資料管理功能與傳統 MySQL 比相差甚遠。本文將在前面實驗的基礎上,將 Hyperledger Fabric 的默認資料庫支持 LevelDB 改為 CouchDB 模式,以實作更復雜的資料... ......

    uj5u.com 2023-04-16 07:28:31 more
  • .NET Core 波場鏈離線簽名、廣播交易(發送 TRX和USDT)筆記

    Get Started NuGet You can run the following command to install the Tron.Wallet.Net in your project. PM> Install-Package Tron.Wallet.Net 配置 public reco ......

    uj5u.com 2023-04-14 08:08:00 more
  • DKP 黑客分析——不正確的代幣對比率計算

    概述: 2023 年 2 月 8 日,針對 DKP 協議的閃電貸攻擊導致該協議的用戶損失了 8 萬美元,因為 execute() 函式取決于 USDT-DKP 對中兩種代幣的余額比率。 智能合約黑客概述: 攻擊者的交易:0x0c850f,0x2d31 攻擊者地址:0xF38 利用合同:0xf34ad ......

    uj5u.com 2023-04-07 07:46:09 more
  • Defi開發簡介

    Defi開發簡介 介紹 Defi是去中心化金融的縮寫, 是一項旨在利用區塊鏈技術和智能合約創建更加開放,可訪問和透明的金融體系的運動. 這與傳統金融形成鮮明對比,傳統金融通常由少數大型銀行和金融機構控制 在Defi的世界里,用戶可以直接從他們的電腦或移動設備上訪問廣泛的金融服務,而不需要像銀行或者信 ......

    uj5u.com 2023-04-05 08:01:34 more
  • solidity簡單的ERC20代幣實作

    // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; import "hardhat/console.sol"; //ERC20 同質化代幣,每個代幣的本質或性質都是相同 //ETH 是原生代幣,它不是ERC20代幣, ......

    uj5u.com 2023-03-21 07:56:29 more
  • solidity 參考型別修飾符memory、calldata與storage 常量修飾符C

    在solidity語言中 參考型別修飾符(參考型別為存盤空間不固定的數值型別) memory、calldata與storage,它們只能修飾參考型別變數,比如字串、陣列、位元組等... memory 適用于方法傳參、返參或在方法體內使用,使用完就會清除掉,釋放記憶體 calldata 僅適用于方法傳參 ......

    uj5u.com 2023-03-08 07:57:54 more
  • solidity注解標簽

    在solidity語言中 注釋符為// 注解符為/* 內容*/ 或者 是 ///內容 注解中含有這幾個標簽給予我們使用 @title 一個應該描述合約/介面的標題 contract, library, interface @author 作者的名字 contract, library, interf ......

    uj5u.com 2023-03-08 07:57:49 more
  • 評價指標:相似度、GAS消耗

    【代碼注釋自動生成方法綜述】 這些評測指標主要來自機器翻譯和文本總結等研究領域,可以評估候選文本(即基于代碼注釋自動方法而生成)和參考文本(即基于手工方式而生成)的相似度. BLEU指標^[^?88^^?^]^:其全稱是bilingual evaluation understudy.該指標是最早用于 ......

    uj5u.com 2023-02-23 07:27:39 more
  • 基于NOSTR協議的“公有制”版本的Twitter,去中心化社交軟體Damus

    最近,一個幽靈,Web3的幽靈,在網路游蕩,它叫Damus,這玩意詮釋了什么叫做病毒式營銷,滑稽的是,一個Web3產品卻在Web2的產品鏈上瘋狂傳銷,各方大佬紛紛為其背書,到底發生了什么?Damus的葫蘆里,賣的是什么藥? 注冊和簡單實用 很少有什么產品在用戶注冊環節會有什么噱頭,但Damus確實出 ......

    uj5u.com 2023-02-05 06:48:39 more