Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

As usual, I recommend random pausing random pausing as a way to see what takes the most time.

That said (I hate saying "that said" because it implies guessing is a good thing - it's not) here's my strong suspicion: A call to calloc only takes a line of code. Does that mean it's cheap? If you single-step it in the disassembly window you'd better bring lunch, because it will take quite a while. So I suspect the samples will show that as your "bottleneck".

You don't really need any extra memory (as @ratchet said) except another temporary array of the same size as the original. You can do your splitting in the original array. Do the merge into the temporary array, and copy back to the original array. That way you malloc only once. (And you should probably free it when you're done.)

And also as @ratchet said, when you get down to small amount, an unrolled bubble sort would probably be faster. Example:

if (amount == 1){
} else if (amount == 2){
 if (data[0] > data[1]) swap(data[0], data[1]);
} else if (amount == 3){
 if (data[0] > data[1]) swap(data[0], data[1]);
 if (data[0] > data[2]) swap(data[0], data[2]);
 if (data[1] > data[2]) swap(data[1], data[2]);
} else if (amount == 4){
 if (data[0] > data[1]) swap(data[0], data[1]);
 if (data[0] > data[2]) swap(data[0], data[2]);
 if (data[0] > data[3]) swap(data[0], data[3]);
 if (data[1] > data[2]) swap(data[1], data[2]);
 if (data[1] > data[3]) swap(data[1], data[3]);
 if (data[2] > data[3]) swap(data[2], data[3]);
} else {
 ... your code ...
}

BTW: You could say:

int amountRight = amount - amountLeft;

As usual, I recommend random pausing as a way to see what takes the most time.

That said (I hate saying "that said" because it implies guessing is a good thing - it's not) here's my strong suspicion: A call to calloc only takes a line of code. Does that mean it's cheap? If you single-step it in the disassembly window you'd better bring lunch, because it will take quite a while. So I suspect the samples will show that as your "bottleneck".

You don't really need any extra memory (as @ratchet said) except another temporary array of the same size as the original. You can do your splitting in the original array. Do the merge into the temporary array, and copy back to the original array. That way you malloc only once. (And you should probably free it when you're done.)

And also as @ratchet said, when you get down to small amount, an unrolled bubble sort would probably be faster. Example:

if (amount == 1){
} else if (amount == 2){
 if (data[0] > data[1]) swap(data[0], data[1]);
} else if (amount == 3){
 if (data[0] > data[1]) swap(data[0], data[1]);
 if (data[0] > data[2]) swap(data[0], data[2]);
 if (data[1] > data[2]) swap(data[1], data[2]);
} else if (amount == 4){
 if (data[0] > data[1]) swap(data[0], data[1]);
 if (data[0] > data[2]) swap(data[0], data[2]);
 if (data[0] > data[3]) swap(data[0], data[3]);
 if (data[1] > data[2]) swap(data[1], data[2]);
 if (data[1] > data[3]) swap(data[1], data[3]);
 if (data[2] > data[3]) swap(data[2], data[3]);
} else {
 ... your code ...
}

BTW: You could say:

int amountRight = amount - amountLeft;

As usual, I recommend random pausing as a way to see what takes the most time.

That said (I hate saying "that said" because it implies guessing is a good thing - it's not) here's my strong suspicion: A call to calloc only takes a line of code. Does that mean it's cheap? If you single-step it in the disassembly window you'd better bring lunch, because it will take quite a while. So I suspect the samples will show that as your "bottleneck".

You don't really need any extra memory (as @ratchet said) except another temporary array of the same size as the original. You can do your splitting in the original array. Do the merge into the temporary array, and copy back to the original array. That way you malloc only once. (And you should probably free it when you're done.)

And also as @ratchet said, when you get down to small amount, an unrolled bubble sort would probably be faster. Example:

if (amount == 1){
} else if (amount == 2){
 if (data[0] > data[1]) swap(data[0], data[1]);
} else if (amount == 3){
 if (data[0] > data[1]) swap(data[0], data[1]);
 if (data[0] > data[2]) swap(data[0], data[2]);
 if (data[1] > data[2]) swap(data[1], data[2]);
} else if (amount == 4){
 if (data[0] > data[1]) swap(data[0], data[1]);
 if (data[0] > data[2]) swap(data[0], data[2]);
 if (data[0] > data[3]) swap(data[0], data[3]);
 if (data[1] > data[2]) swap(data[1], data[2]);
 if (data[1] > data[3]) swap(data[1], data[3]);
 if (data[2] > data[3]) swap(data[2], data[3]);
} else {
 ... your code ...
}

BTW: You could say:

int amountRight = amount - amountLeft;
added 319 characters in body
Source Link

As usual, I recommend random pausing as a way to see what takes the most time.

That said (I hate saying "that said" because it implies guessing is a good thing - it's not) here's my strong suspicion: A call to calloc only takes a line of code. Does that mean it's cheap? If you single-step it in the disassembly window you'd better bring lunch, because it will take quite a while. So I suspect the samples will show that as your "bottleneck".

You don't really need any extra memory (as @ratchet said) except another temporary array of the same size as the original. You can do your splitting in the original array. Do the merge into the temporary array, and copy back to the original array. That way you malloc only once. (And you should probably free it when you're done.)

And also as @ratchet said, when you get down to small amount, an unrolled bubble sort would probably be faster. Example:

if (amount == 1){
} else if (amount == 2){
 if (data[1]data[0] <> data[0]data[1]) swap(data[1]data[0], data[0]data[1]);
} else if (amount == 3){
 if (data[0] > data[1]) <swap(data[0], data[1]);
  if (data[0] > data[2]) swap(data[1]data[0], data[0]data[2]);
 if (data[1] > data[2]) swap(data[1], data[2]);
} <else if (amount == 4){
  if (data[0] > data[1]) swap(data[0], data[1]);
 if (data[0] > data[2]) swap(data[0], data[2]);
  if (data[0] > data[3]) swap(data[0], data[3]);
 if (data[1] > data[2]) <swap(data[1], data[2]);
  if (data[1] > data[3]) swap(data[1], data[3]);
 if (data[2] > data[3]) swap(data[2], data[1]data[3]);
} else {
 ... your code ...
}

BTW: You could say:

int amountRight = amount - amountLeft;

As usual, I recommend random pausing as a way to see what takes the most time.

That said (I hate saying "that said" because it implies guessing is a good thing - it's not) here's my strong suspicion: A call to calloc only takes a line of code. Does that mean it's cheap? If you single-step it in the disassembly window you'd better bring lunch, because it will take quite a while. So I suspect the samples will show that as your "bottleneck".

You don't really need any extra memory (as @ratchet said) except another temporary array of the same size as the original. You can do your splitting in the original array. Do the merge into the temporary array, and copy back to the original array. That way you malloc only once. (And you should probably free it when you're done.)

And also as @ratchet said, when you get down to small amount, an unrolled bubble sort would probably be faster. Example:

if (amount == 1){
} else if (amount == 2){
 if (data[1] < data[0]) swap(data[1], data[0]);
} else if (amount == 3){
 if (data[1] < data[0]) swap(data[1], data[0]);
 if (data[2] < data[0]) swap(data[2], data[0]);
 if (data[2] < data[1]) swap(data[2], data[1]);
} else {
 ... your code ...
}

BTW: You could say:

int amountRight = amount - amountLeft;

As usual, I recommend random pausing as a way to see what takes the most time.

That said (I hate saying "that said" because it implies guessing is a good thing - it's not) here's my strong suspicion: A call to calloc only takes a line of code. Does that mean it's cheap? If you single-step it in the disassembly window you'd better bring lunch, because it will take quite a while. So I suspect the samples will show that as your "bottleneck".

You don't really need any extra memory (as @ratchet said) except another temporary array of the same size as the original. You can do your splitting in the original array. Do the merge into the temporary array, and copy back to the original array. That way you malloc only once. (And you should probably free it when you're done.)

And also as @ratchet said, when you get down to small amount, an unrolled bubble sort would probably be faster. Example:

if (amount == 1){
} else if (amount == 2){
 if (data[0] > data[1]) swap(data[0], data[1]);
} else if (amount == 3){
 if (data[0] > data[1]) swap(data[0], data[1]);
  if (data[0] > data[2]) swap(data[0], data[2]);
 if (data[1] > data[2]) swap(data[1], data[2]);
} else if (amount == 4){
  if (data[0] > data[1]) swap(data[0], data[1]);
 if (data[0] > data[2]) swap(data[0], data[2]);
  if (data[0] > data[3]) swap(data[0], data[3]);
 if (data[1] > data[2]) swap(data[1], data[2]);
  if (data[1] > data[3]) swap(data[1], data[3]);
 if (data[2] > data[3]) swap(data[2], data[3]);
} else {
 ... your code ...
}

BTW: You could say:

int amountRight = amount - amountLeft;
added 319 characters in body
Source Link

As usual, I recommend random pausing as a way to see what takes the most time.

That said (I hate saying "that said" because it implies guessing is a good thing - it's not) here's my strong suspicion: A call to calloc only takes a line of code. Does that mean it's cheap? If you single-step it in the disassembly window you'd better bring lunch, because it will take quite a while. So I suspect the samples will show that as your "bottleneck".

You don't really need any extra memory (as @ratchet said) except another temporary array of the same size as the original. You can do your splitting in the original array. Do the merge into the temporary array, and copy back to the original array. That way you malloc only once. (And you should probably free it when you're done.)

And also as @ratchet said, when you get down to small amount, an unrolled bubble sort would probably be faster. Example:

if (amount == 1){
} else if (amount == 2){
 if (data[1] < data[0]) swap(data[1], data[0]);
} else if (amount == 3){
 if (data[1] < data[0]) swap(data[1], data[0]);
 if (data[2] < data[0]) swap(data[2], data[0]);
 if (data[2] < data[1]) swap(data[2], data[1]);
} else {
 ... your code ...
}

BTW: You could say:

int amountRight = amount - amountLeft;

As usual, I recommend random pausing as a way to see what takes the most time.

That said (I hate saying "that said" because it implies guessing is a good thing - it's not) here's my strong suspicion: A call to calloc only takes a line of code. Does that mean it's cheap? If you single-step it in the disassembly window you'd better bring lunch, because it will take quite a while. So I suspect the samples will show that as your "bottleneck".

You don't really need any extra memory (as @ratchet said) except another temporary array of the same size as the original. You can do your splitting in the original array. Do the merge into the temporary array, and copy back to the original array. That way you malloc only once. (And you should probably free it when you're done.)

And also as @ratchet said, when you get down to small amount, an unrolled bubble sort would probably be faster.

BTW: You could say:

int amountRight = amount - amountLeft;

As usual, I recommend random pausing as a way to see what takes the most time.

That said (I hate saying "that said" because it implies guessing is a good thing - it's not) here's my strong suspicion: A call to calloc only takes a line of code. Does that mean it's cheap? If you single-step it in the disassembly window you'd better bring lunch, because it will take quite a while. So I suspect the samples will show that as your "bottleneck".

You don't really need any extra memory (as @ratchet said) except another temporary array of the same size as the original. You can do your splitting in the original array. Do the merge into the temporary array, and copy back to the original array. That way you malloc only once. (And you should probably free it when you're done.)

And also as @ratchet said, when you get down to small amount, an unrolled bubble sort would probably be faster. Example:

if (amount == 1){
} else if (amount == 2){
 if (data[1] < data[0]) swap(data[1], data[0]);
} else if (amount == 3){
 if (data[1] < data[0]) swap(data[1], data[0]);
 if (data[2] < data[0]) swap(data[2], data[0]);
 if (data[2] < data[1]) swap(data[2], data[1]);
} else {
 ... your code ...
}

BTW: You could say:

int amountRight = amount - amountLeft;
added 113 characters in body
Source Link
Loading
Source Link
Loading
lang-c

AltStyle によって変換されたページ (->オリジナル) /