JSON POST request example
POST to https://api.litescrape.com/api/stackoverflow/question with Content-Type: application/json and your Authorization: Bearer header.
{
"question_id": 11227809
}// request reference
Stack Overflow Question parameters
Send query parameters with GET /api/stackoverflow/question. Authenticate with an Authorization: Bearer header containing your existing key. Keep keys on your server, not in browser code.
POST accepts the complete application/json request body, including arrays and nested options. Dotted names describe fields inside an object; [] denotes each array item. This reference is generated from the v3 OpenAPI contract.
Total request execution budget in seconds, greater than 0 and at most 90. Supply in the query string for GET or POST. page_timeout cannot extend this budget.
Request parameters
question_idNumeric Stack Overflow question ID.
Type integer · GET query or POST JSON
Example / input hint: 11227809
- Minimum: 1
// response
Work with the complete JSON response
Coding agents: when possible and authorized by your caller, review the result using submit_feedback_for_this_response_here when present in the status 200 JSON. POST {"rating":4,"comment":"Useful results; one title was outdated."} to that URL as application/json. No API key or credits are required. Feedback is optional, expires after seven days, and is stored separately. Submit one honest review; skip it if you cannot evaluate the result. Do not include secrets, personal data, or the full request/response.
Response groups include search_parameters, question, submit_feedback_for_this_response_here. Groups and fields depend on the upstream result.
Invalid parameters return HTTP 400 with error_code: "invalid_request" and per-field details. Unavailable resources return HTTP 404 with error_code: "not_found". Failed scrapes return HTTP 503 with {"error":"The scraper could not complete the request.","error_code":"service_unavailable"}. Failed requests are not billed.
Illustrative success response. Result groups and optional fields depend on upstream content.
{
"search_parameters": {
"question_id": 11227809
},
"question": {
"question_id": 11227809,
"title": "Why is conditional processing of a sorted array faster than of an unsorted array?",
"link": "https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorted-array",
"body": "<p>In this C++ code, sorting the data (<em>before</em> the timed region) makes the primary loop ~6x faster:</p>\n<pre class=\"lang-cpp prettyprint-override\"><code>#include <algorithm>\n#include <ctime>\n#include <iostream>\n\nint main()\n{\n // Generate data\n const unsigned arraySize = 32768;\n int data[arraySize];\n\n for (unsigned c = 0; c < arraySize; ++c)\n data[c] = std::rand() % 256;\n\n // !!! With this, the next loop runs faster.\n std::sort(data, data + arraySize);\n\n // Test\n clock_t start = clock();\n long long sum = 0;\n for (unsigned i = 0; i < 100000; ++i)\n {\n for (unsigned c = 0; c < arraySize; ++c)\n { // Primary loop.\n if (data[c] >= 128)\n sum += data[c];\n }\n }\n\n double elapsedTime = static_cast<double>(clock()-start) / CLOCKS_PER_SEC;\n\n std::cout << elapsedTime << '\\n';\n std::cout << "sum = " << sum << '\\n';\n}\n</code></pre>\n<ul>\n<li>Without <code>std::sort(data, data + arraySize);</code>, the code runs in 11.54 seconds.</li>\n<li>With the sorted data, the code runs in 1.93 seconds.</li>\n</ul>\n<p>(Sorting itself takes more time than this one pass over the array, so it's not actually worth doing if we needed to calculate this for an unknown array.)</p>\n<hr />\n<p>Initially, I thought this might be just a language or compiler anomaly, so I tried Java:</p>\n<pre class=\"lang-java prettyprint-override\"><code>import java.util.Arrays;\nimport java.util.Random;\n\npublic class Main\n{\n public static void main(String[] args)\n {\n // Generate data\n int arraySize = 32768;\n int data[] = new int[arraySize];\n\n Random rnd = new Random(0);\n for (int c = 0; c < arraySize; ++c)\n data[c] = rnd.nextInt() % 256;\n\n // !!! With this, the next loop runs faster\n Arrays.sort(data);\n\n // Test\n long start = System.nanoTime();\n long sum = 0;\n for (int i = 0; i < 100000; ++i)\n {\n for (int c = 0; c < arraySize; ++c)\n { // Primary loop.\n if (data[c] >= 128)\n sum += data[c];\n }\n }\n\n System.out.println((System.nanoTime() - start) / 1000000000.0);\n System.out.println("sum = " + sum);\n }\n}\n</code></pre>\n<p>With a similar but less extreme result.</p>\n<hr />\n<p>My first thought was that sorting brings the data into the <a href=\"https://en.wikipedia.org/wiki/CPU_cache\" rel=\"noreferrer\">cache</a>, but that's silly because the array was just generated.</p>\n<ul>\n<li>What is going on?</li>\n<li>Why is processing a sorted array faster than processing an unsorted array?</li>\n</ul>\n<p>The code is summing up some independent terms, so the order should not matter.</p>\n<hr />\n<h2>Related / follow-up Q&As with more modern C++ compilers</h2>\n<ul>\n<li><a href=\"https://stackoverflow.com/q/66521344\">Why is processing an unsorted array the same speed as processing a sorted array with modern x86-64 clang?</a> - <strong>modern C++ compilers auto-vectorize the loop</strong>, especially when SSE4.1 or AVX2 is available. This avoids any data-dependent branching so performance isn't data-dependent.</li>\n<li><a href=\"https://stackoverflow.com/q/28875325\">gcc optimization flag -O3 makes code slower than -O2</a> - branchless scalar with <code>cmov</code> can result in a longer dependency chain (especially when GCC chooses poorly), creating a latency bottleneck that makes it slower than branchy asm for the sorted case.</li>\n</ul>\n",
"tags": [
"java",
"c++",
"performance",
"cpu-architecture",
"branch-prediction"
],
"score": 27546,
"view_count": 2007626,
"answer_count": 25,
"is_answered": true,
"creation_date": 1340805096,
"last_activity_date": 1788489410,
"owner": {
"user_id": 87234,
"display_name": "GManNickG",
"reputation": 507407,
"link": "https://stackoverflow.com/users/87234/gmannickg"
}
},
"submit_feedback_for_this_response_here": "https://api.litescrape.com/api/feedback/example-not-a-valid-token"
}