C: Unterschied zwischen den Versionen

Aus Info-Theke
Zur Navigation springen Zur Suche springen
 
(13 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;
typedef struct {
seed_t m_seed;
seed_t m_factor;
seed_t m_offset;
seed_t m_x;
seed_t m_y;
seed_t m_z;
seed_t m_c;
} Random;
 
void init(Random* rand){
rand->m_seed = 0x20111958UL;
rand->m_factor = 0x323abceUL;
rand->m_offset = 0x1234321UL;
rand->m_x = 0x33221122UL;
rand->m_y = 0x73829382UL;
rand->m_z = 0xabcdef07UL;
rand->m_c = 0;
}
long next(Random* rand){
// linear congruence generator:
rand->m_x = rand->m_x * rand->m_factor + rand->m_offset;
// XorShift:
rand->m_y ^= rand->m_y << 13;
rand->m_y ^= rand->m_y >> 17;
rand->m_y ^= rand->m_y << 5;
// Multiply with carry:
seed_t t = 698769069UL * rand->m_z + rand->m_c;
rand->m_c = t << 32;
rand->m_z = t;
rand->m_seed = rand->m_x + rand->m_y + rand->m_z;
return rand->m_seed;
}
 
seed_t random(int millions){
Random rand;
seed_t rc = 0;
int ix;
init(&rand);
while (millions-- > 0){
int ix2 = 1000000;
while(ix2-- > 0)
rc += next(&rand);
}
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 = random(millions);
duration = clock() - start;
printf ("%.3f sec %.3f HamaMips %d\n",  duration / (double) CLOCKS_PER_SEC,
millions * (double) CLOCKS_PER_SEC / duration, value);
}
</pre>

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