C: Unterschied zwischen den Versionen

Aus Info-Theke
Zur Navigation springen Zur Suche springen
 
(11 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
[[Kategorie:Sprache]]
[[Kategorie:Sprache]]


== big.c (schnell Platte füllen) ==
= Links =
<pre>#include <stdio.h>
* [[C]]
#include <stdlib.h>
* [[C-Beispiel-big.c]] Platte schnell füllen
* [[C-hamamips.c]] CPU-Benchmark
== Tutorials ==
* [https://www.learn-c.org/de/ learn-c.org (deutsch)]
* [http://www.c-programmieren.com/C-Lernen.html C-Lernen (deutsch), sehr ausführlich]


int main(int count, char** arg){
= Umgebung =
  FILE* file = fopen("big.data", "w");
* [https://www.heise.de/download/product/virtual-c-ide-94038 virtual-c: Live-Coding IDE mit Debugger]
  int size = 0x10000 * 128;
* [https://bloodshed-dev-c.de.softonic.com/ bloodshed-dev-c: Einfache IDE mittels MINGW]
  void* data = calloc(size, 1);
* [http://www.codeblocks.org/ codeblocks: Editor mit MINGW]
  int mByte = 0;
  while (fwrite(data, size, 1, file) > 0){
    mByte += size / 1024 / 1024;
    printf("%d MByte\n", mByte);
  }
  return 0;
}
</pre>


== CPU-Benchmark hamamips.c ==
= Ideen =
<pre>#include "stdio.h"
* Random-Generator
#include "stdlib.h"
* Verschlüsselung
#include "time.h"
* Tankprotokoll
typedef unsigned long seed_t;
#define DEFINE_VARS(seed, x, y, z, c) seed_t seed = 0x20111958UL; \
seed_t x = 0x33221122UL; \
seed_t y = 0x73829382UL; \
seed_t z = 0xabcdef07UL; \
seed_t c = 0
#define next(seed, x, y, z, c) \
do { \
x = x * 0x20111957 + 0x11121989; \
y ^= y << 13; \
y ^= y >> 17; \
y ^= y << 5; \
seed_t t = 698769069UL * z + c; \
c = t << 32; \
z = t; \
seed = x + y + z; \
} while (0)
seed_t calcRandom(int millions){
DEFINE_VARS(seed, x, y, z, c);
seed_t rc = 0;
while (millions-- > 0){
int ix2 = 1000000;
while(ix2-- > 0){
next(seed, x, y, z, c);
rc += seed;
}
}
return rc;
}
int main(int argc, char** argv){
clock_t start = clock();
seed_t value;
clock_t duration;
int millions = 100;
if (argc > 1 && atol(argv[1]) != 0)
millions = atol(argv[1]);
value = calcRandom(millions);
duration = clock() - start;
printf ("%.3f HamaMips %.3f sec value: %d\n", 
millions * (double) CLOCKS_PER_SEC / duration,
duration / (double) CLOCKS_PER_SEC,
value);
}
</pre>

Aktuelle Version vom 14. Juni 2020, 09:01 Uhr