Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions hw2/graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

test_data = open("time.txt", "r")
lines = test_data.readlines()
time = []
n = []
for line in lines:
line = line.strip('\n ] [ ').split(' ')
time.append(int(line[1]))
n.append(int(line[0]))
test_data.close()
time.sort()
n.sort()
x = n[:-1]
y = time[:-1]
plt.plot(x, y, label="the relationship between N and the execution time")
plt.legend()
plt.xlabel("N")
plt.ylabel("time")
plt.savefig('time.png')
20 changes: 20 additions & 0 deletions hw2/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ func newMatrix(n int) [][]int {
return m
}

func failOnError(err error) {
if err != nil {
log.Fatal("Error:", err)
}
}

func main() {
if len(os.Args) < 2 {
fmt.Println("usage: go run matrix.go N")
Expand Down Expand Up @@ -85,4 +91,18 @@ func main() {
if want != 0 && total != want {
fmt.Printf("Wanted sum %v but got %v\n", want, total)
}

var n_str string
var time_str string
n_str = strconv.Itoa(n)
time_str = strconv.Itoa(int(end.Sub(begin)))

file, err := os.OpenFile("time.txt", os.O_WRONLY|os.O_APPEND, 0600)
if err != nil {
log.Fatal(err)
}
defer file.Close()

fmt.Fprintln(file, []string{n_str, time_str})

}
Binary file added hw2/time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions hw2/time.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[1 276]
[2 334]
[3 537]
[4 473]
[5 633]
[6 861]
[7 1207]
[8 1701]
[9 2318]
[10 4244]
[50 351532]
[100 3060330]
[200 27809659]
[300 122514780]
[400 302434663]
[400 280376609]
[500 621763472]
[600 1039208850]
[700 2155400336]
[800 2794530550]
[900 11907044262]
[1000 15037068087]