#include <iostream>
#include <cstdio>
#include <ctime>
using namespace std;
void printArray(int array[], int size) {
for (int i = 0; i < size; i++) {
cout << array[i] << " ";
}
cout << endl;
}
void insertionSort(int array[], int size) {
for (int step = 1; step < size; step++) {
int key = array[step];
int j = step - 1;
while (j >=0 && key < array[j]) {
array[j + 1] = array[j];
--j;
}
array[j + 1] = key;
}
}
int main() {
std::clock_t start;
double duration;
start = std::clock();
int data[] = {1000,100,10000,1000000};
int size = sizeof(data) / sizeof(data[0]);
insertionSort(data, size);
cout << "Sorted array in ascending order:\n";
printArray(data, size);
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
std::cout<<"printf: "<< duration <<'\n';
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y3RpbWU+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIHByaW50QXJyYXkoaW50IGFycmF5W10sIGludCBzaXplKSB7CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBzaXplOyBpKyspIHsKICAgIGNvdXQgPDwgYXJyYXlbaV0gPDwgIiAiOwogIH0KICBjb3V0IDw8IGVuZGw7Cn0KCnZvaWQgaW5zZXJ0aW9uU29ydChpbnQgYXJyYXlbXSwgaW50IHNpemUpIHsKICBmb3IgKGludCBzdGVwID0gMTsgc3RlcCA8IHNpemU7IHN0ZXArKykgewogICAgaW50IGtleSA9IGFycmF5W3N0ZXBdOwogICAgaW50IGogPSBzdGVwIC0gMTsKCiAgICB3aGlsZSAoaiA+PTAgJiYga2V5IDwgYXJyYXlbal0pIHsKICAgICAgYXJyYXlbaiArIDFdID0gYXJyYXlbal07CiAgICAgIC0tajsKICAgIH0KICAgIGFycmF5W2ogKyAxXSA9IGtleTsKICB9Cn0KCmludCBtYWluKCkgewoJIHN0ZDo6Y2xvY2tfdCBzdGFydDsKICAgIGRvdWJsZSBkdXJhdGlvbjsKCiAgICBzdGFydCA9IHN0ZDo6Y2xvY2soK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