mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-20 02:57:19 +03:00
Simplify benchmark kitten
On macOS reading from the same tty device file as we are writing too in another thread gives continuous EAGAIN errors. We dont actually need simultaneous read/write, so move the reads to the end.
This commit is contained in:
parent
0fcb055246
commit
4eb49b3320
@ -60,26 +60,8 @@ func benchmark_data(description string, data string, opts Options) (duration tim
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer func() { _ = write_with_retry(state.ResetStateEscapeCodes() + reset) }()
|
defer func() { _ = write_with_retry(state.ResetStateEscapeCodes() + reset) }()
|
||||||
lock := sync.Mutex{}
|
|
||||||
const count = 3
|
const count = 3
|
||||||
goroutine_started := make(chan byte)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
lock.Lock()
|
|
||||||
defer lock.Unlock()
|
|
||||||
buf := make([]byte, 8192)
|
|
||||||
var data []byte
|
|
||||||
q := []byte(strings.Repeat("\x1b[0n", count))
|
|
||||||
goroutine_started <- 'y'
|
|
||||||
for !bytes.Contains(data, q) {
|
|
||||||
n, err := term.Read(buf)
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
data = append(data, buf[:n]...)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
<-goroutine_started
|
|
||||||
const clear_screen = "\x1b[H\x1b[2J\x1b[m"
|
const clear_screen = "\x1b[H\x1b[2J\x1b[m"
|
||||||
desc := clear_screen + "Running: " + description + "\r\n"
|
desc := clear_screen + "Running: " + description + "\r\n"
|
||||||
const pause_rendering = "\x1b[?2026h"
|
const pause_rendering = "\x1b[?2026h"
|
||||||
@ -103,18 +85,25 @@ func benchmark_data(description string, data string, opts Options) (duration tim
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err = write_with_retry(clear_screen + "Waiting for response indicating parsing finished\r\n" + strings.Repeat("\x1b[5n", count)); err != nil {
|
finalize := clear_screen + "Waiting for response indicating parsing finished\r\n"
|
||||||
|
if !opts.Render {
|
||||||
|
finalize += resume_rendering
|
||||||
|
}
|
||||||
|
finalize += strings.Repeat("\x1b[5n", count)
|
||||||
|
if err = write_with_retry(finalize); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !opts.Render {
|
q := []byte(strings.Repeat("\x1b[0n", count))
|
||||||
if err = write_with_retry(resume_rendering); err != nil {
|
var read_data []byte
|
||||||
return
|
buf := make([]byte, 8192)
|
||||||
|
for !bytes.Contains(read_data, q) {
|
||||||
|
n, err := term.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
read_data = append(read_data, buf[:n]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
lock.Lock()
|
|
||||||
duration = time.Since(start)
|
duration = time.Since(start)
|
||||||
lock.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user