Skip to content

Instantly share code, notes, and snippets.

@dnbaker
Last active October 17, 2017 05:04
Show Gist options
  • Select an option

  • Save dnbaker/1256ef4aefafe23a4a95cdf2cdb42a48 to your computer and use it in GitHub Desktop.

Select an option

Save dnbaker/1256ef4aefafe23a4a95cdf2cdb42a48 to your computer and use it in GitHub Desktop.
Very fast yes command (4x as fast as gnu coreutils)
#include <cstdio>
#include <cstring>
#include <string>
#include "unistd.h"
#ifndef _BUF_SZ__
#define _BUF_SZ__ 1 << 16
#endif
int main(int argc, char *argv[]) {
const char *val(argc > 1 ? argv[1]: "y");
std::string data;
while(data.size() + std::strlen(val) < _BUF_SZ__) data += val, data += '\n';
while(write(STDOUT_FILENO, data.data(), data.size()));
return EXIT_FAILURE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment