Added analysis.

This commit is contained in:
retoor 2024-12-31 00:00:43 +01:00
parent 2bbde0ee8b
commit f5321397f4
7 changed files with 420 additions and 0 deletions

192
.clang-format Normal file
View File

@ -0,0 +1,192 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 140
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
PackConstructorInitializers: BinPack
BasedOnStyle: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
AllowAllConstructorInitializersOnNextLine: true
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
BeforeNonEmptyParentheses: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.backup*

View File

@ -20,6 +20,10 @@ There are three ways to install the package:
```bash ```bash
./rd ./rd
``` ```
# Some interesting stats
Especially if you know the the data.
![stats](analysis.png)
# Example output: # Example output:
```bash ```bash

BIN
analysis.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

31
build.py Normal file
View File

@ -0,0 +1,31 @@
@task
def format():
"""
Formats source code.
"""
system("clang-format -i *.c")
@task
def publish():
"""
Publish binary to molodetz.nl package manager.
"""
system("publish rd")
@task
def build():
"""
Formats and builds rd executable.
"""
format()
system("gcc -o rd rd.c -Ofast -Werror -Wall -pedantic -Wextra")
@task
def run():
"""
Format, build and run rd.
"""
build()
os.system("./rd")

BIN
rd Executable file

Binary file not shown.

192
rd.c Normal file
View File

@ -0,0 +1,192 @@
/*
Written by retoor@molodetz.nl
This C program generates random characters, integers, and tokens and outputs them in different formats based on command-line arguments. The
program continuously generates data, which can be useful for testing data streams or simulating input.
This source code uses the following non-standard library includes:
- <string.h> for handling string operations.
- <time.h> for random seed initialization.
- <stdlib.h> for memory allocation and random functions.
The MIT License (MIT)
Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and associated documentation files(the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions : The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS",
WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
char *chars = "abcdefghijklmnopqrstuvwxyz123456789";
int char_index = 0;
unsigned char byte = 0;
unsigned char next_byte() {
byte = (byte + 1) % 254;
return byte;
}
char get_char() {
char c = chars[char_index];
char_index = (char_index + 1) % strlen(chars);
return c;
}
unsigned int current_int = 0;
unsigned int bytes_written = 0;
unsigned randoms[10000];
unsigned randoms_index = 0;
unsigned int get_next_random() {
randoms_index = (randoms_index ^ 254) % (sizeof(randoms) / sizeof(int));
randoms_index = (randoms_index ^ 33) % randoms_index;
if (randoms_index % 3)
randoms_index ^= 1337;
return randoms[randoms_index] ^ randoms_index ^ 1337 ^ rand();
}
unsigned int get_int(int max) {
current_int = (current_int + 1) % max;
current_int = (get_next_random() + current_int) % max;
return current_int;
}
const char *get_random_token() {
const char *tokens[] = {"OR",
"30",
"\xF0\x9F\x98\x8D",
"\xF0\x9F\x98\x98",
"42",
"420",
"\xF0\x9F\x98\x88",
"\xF0\x9F\x98\x82",
"19",
"16",
"\xF0\x9F\x99\x89",
"\xF0\x9F\x98\x86",
"71",
"\xF0\x9F\x98\x9E",
"83",
"\xF0\x9F\x98\x8A",
"\xF0\x9F\x98\x82",
"\xF0\x9F\x98\xB0",
"\xF0\x9F\x98\x92",
"RE",
"\xF0\x9F\x99\x88",
"1",
"\xF0\x9F\x98\x9C",
"37",
"\xF0\x9F\x98\xA8",
"90",
"51",
"\xF0\x9F\x98\xB1",
"93",
"58",
"\xF0\x9F\x98\x81",
"04",
"84",
"TO",
"84",
"27",
"10",
"0",
"\xF0\x9F\x98\xA9",
"6",
"\xF0\x9F\x99\x8A",
"\xF0\x9F\x98\x84",
"+3",
"13"};
size_t count = sizeof(tokens) / sizeof(tokens[0]);
int random_index = get_int(count);
bytes_written++;
return tokens[random_index];
}
char *create_batch(int batch_size) {
static char buffer[1024 * 10] = {0};
while ((int)strlen(buffer) < batch_size) {
strcat(buffer, get_random_token());
}
return buffer;
}
void utf8() {
for (;;) {
printf("%s", get_random_token());
}
}
void chunked(int size) {
for (;;) {
char *b = create_batch(size);
printf("%s", b);
}
}
void lines(int size) {
for (;;) {
char *b = create_batch(size);
printf("%s\r\n", b);
}
}
void ints() {
const int random_cipher = 1337;
for (;;) {
printf("%u", get_int(random_cipher));
}
}
void intsc() {
const int random_cipher = 42;
for (;;) {
printf("%u,", get_int(random_cipher));
}
}
int main(int argc, char **argv) {
setbuf(stdout, NULL);
srand((unsigned int)time(NULL));
for (size_t i = 0; i < sizeof(randoms) / sizeof(int); i++) {
randoms[i] = rand();
}
for (int i = 1; i < argc; i++) {
if (strstr(argv[i], "utf8")) {
utf8();
return 0;
}
if (strstr(argv[i], "utf8c")) {
const int chunk_size = 1024;
chunked(chunk_size);
return 0;
}
if (strstr(argv[i], "utf8l")) {
const int length = 50;
lines(length);
return 0;
}
if (strstr(argv[i], "ints")) {
ints();
return 0;
}
if (strstr(argv[i], "intsc")) {
intsc();
return 0;
}
}
utf8();
return 0;
}