-
Notifications
You must be signed in to change notification settings - Fork 3
/
turbo.rs
37 lines (35 loc) · 1.1 KB
/
turbo.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::fs::File;
use std::io::{stdout, Write};
use std::os::unix::io::{AsRawFd, FromRawFd};
fn increase_str_num(input: &mut [u8]) -> usize {
let input_size = input.len();
for i in (0..input_size).rev() {
input[i] += 1;
if input[i] - b'0' < 10 {
return input_size - i;
}
input[i] = b'0';
}
panic!("overflowed input");
}
fn main() {
let stdout = AsRawFd::as_raw_fd(&stdout());
let mut stdout: File = unsafe { FromRawFd::from_raw_fd(stdout) };
const BUFSIZ: usize = 8192;
let mut buffer = Vec::with_capacity(BUFSIZ);
let mut num = [b'0'; 12];
let mut num_len = 1;
let prefix = b"Hello, ";
const LINE_MAX_LEN: usize = 17;
for _ in 0..100_000_000 {
buffer.extend_from_slice(prefix);
buffer.extend_from_slice(&num[num.len() - num_len..]);
num_len = num_len.max(increase_str_num(&mut num));
buffer.push(b'\t');
if buffer.len() + LINE_MAX_LEN > BUFSIZ {
let _ = stdout.write(&buffer).unwrap();
buffer.clear();
}
}
let _ = stdout.write(&buffer).unwrap();
}