Skip to main content
Tweeted twitter.com/StackCodeReview/status/792376868997570564
deleted 4 characters in body; edited tags; edited title; added 3 characters in body; edited tags; deleted 2 characters in body; deleted 2 characters in body; deleted 4 characters in body; added 2 characters in body; edited title; edited tags
Source Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

Golang - Faster Way to Find and Print all Lines containinglines of a Word ina Filetext file containing the same duplicated word

I'm realizingimplementing my very first GoGo application and I would like to receive an hint on how to make a certain check faster.

Where key is ALWAYS 6 HEX digits long6 HEX digits long and text is ALWAYS 16 HEX digits long16 HEX digits long.

  • 000000 1234567890123456
  • 111111 1234567890123456
  • 000000 1234567890123456
  • 111111 1234567890123456

It works just fine but, since I have million lines, it's really slow. I'm only capable of doing it with a single thread and not using goroutinesgoroutines.

Have you any suggestion on how Should I change this code to speed up the check? Have you any suggestion on how I should change this code to speed up the check?

Golang - Faster Way to Find and Print all Lines containing a Word ina File

I'm realizing my very first Go application and I would like to receive an hint on how to make a certain check faster.

Where key is ALWAYS 6 HEX digits long and text is ALWAYS 16 HEX digits long.

  • 000000 1234567890123456
  • 111111 1234567890123456

It works just fine but, since I have million lines, it's really slow. I'm only capable of doing it with a single thread and not using goroutines.

Have you any suggestion on how Should I change this code to speed up the check?

Print all lines of a text file containing the same duplicated word

I'm implementing my very first Go application and I would like to receive an hint on how to make a certain check faster.

Where key is ALWAYS 6 HEX digits long and text is ALWAYS 16 HEX digits long.

  • 000000 1234567890123456
  • 111111 1234567890123456

It works just fine but, since I have million lines, it's really slow. I'm only capable of doing it with a single thread and not using goroutines.

Have you any suggestion on how I should change this code to speed up the check?

deleted 20 characters in body
Source Link
janos
  • 113.1k
  • 15
  • 154
  • 396

Thanks in advance.

Thanks in advance.

Source Link

Golang - Faster Way to Find and Print all Lines containing a Word ina File

I'm realizing my very first Go application and I would like to receive an hint on how to make a certain check faster.

I have a huge txt file in which each line is structured like the following:

key text
key text
   .
   .
key text

Where key is ALWAYS 6 HEX digits long and text is ALWAYS 16 HEX digits long.

I need to find and print all the lines which have the same text value. For instance, suppose we have 2 lines like the following

  • 000000 1234567890123456
  • 111111 1234567890123456

They should be both printed.

Here's my code:

r, _ := os.Open("store.txt")
    scanner := bufio.NewScanner(r)
    for scanner.Scan() {
        line := scanner.Text()
        text := line[7:]
        if !contains(duplicates, text) {
            duplicates = append(duplicates, text)
        } else {
                t, _:= os.Open("store.txt")
                dupScan := bufio.NewScanner(t)
                    //currLine := dupScan.Text()
                for dupScan.Scan() {
                    currLine   := dupScan.Text()
                    currCipher := currLine[7:23]
                    if( currCipher == text ){
                    fmt.Println(currLine)
                    }
                }
                t.Close()
            }
    }
fmt.Println("Done Check")
//Close File
r.Close()

func contains(s []string, e string) bool {
    for _, a := range s {
        if a == e {
            return true
        }
    }
    return false
}

It works just fine but, since I have million lines, it's really slow. I'm only capable of doing it with a single thread and not using goroutines.

Have you any suggestion on how Should I change this code to speed up the check?

Thanks in advance.