python – Why is my Sieve of Eratosthenes using generators so slow

This is my prime sieve based on the Sieve of Eratosthenes.

import itertools
sieve = itertools.count(2)
primes = ()
nprime = 0
for _ in range(10000):
    nprime = next(sieve)
    primes.append(nprime)
    sieve = filter(eval(f"lambda x: x % {nprime} != 0"), sieve)

On my computer this code takes 13.4 seconds to generate 10,000 primes.

Edit:
As suggested by Dannnno, replacing eval(f"lambda x: x % {nprime} != 0")
with asmod(nprime) with asmod defined as:

def asmod(a):
    def inner(x):
        return x % a != 0
    return inner

improves the efficiency of the code.

windows 10 – Slow wifi on one device due to poor hardware

I have two computers. A laptop and a desktop. Speed test on the laptop shows a download speed of 156Mbps. Speed test on desktop shows a download speed of 2Mbps. I can also see the difference in speed while using these devices.
I tried to google the reason but none of the solutions talk about poor hardware. I strongly suspect that my desktop has poor hardware. But I have no idea about the hardware components.

Which hardware component manages wifi? Is there a good way to know if the slow wifi speed is due to poor hardware?
I want to know so that I can replace this hardware component

Hardware issues with a slow mid-2012 Macbook Air 13" (A1466) [closed]

I’ve had it since it first came out and they’re finally starting to give way. Maybe it’s because I was rough with them, but I hoped they last me a little longer (or at least until after university). I use them mostly for work now (Microsoft Office and Adobe Photoshop) but I did game on them lots when I was younger, so that’s probably where the damage comes from.

The Macbook Air is slow. It’s very slow:

  • It stops 3/4ths of the way in the loading screen, it takes 30 mins to boot up.
  • Even after it’s booted up, applications take ages to load and the cursor lags hard. Typing takes a while too.
  • More than half of its RAM is empty, trash is empty.
  • Did Apple diagnostics and EFI/Drivers/TestSupport.efi can’t be loaded.
  • The battery appears as an "X" and won’t last a second without a charger plugged into it.

How should I go about fixing it? I’m not really in a position to send it to repair — I do want to learn how to fix issues should they happen again.

Thank you very much. Any help would be very much appreciated.

magento2 – Magento 2: Layered navigation $filter->getItemsCount() very slow

We are using layered navigation and are loading a filter block in sidebar. But $filter->getItemsCount() takes a long time to load.

<?php foreach ($block->getFilters() as $filter): ?>
                    <?php if (!$wrapOptions): ?>
                        <strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?= $block->escapeHtml(__('Shopping Options')) ?></strong>
                        <div class="filter-options" id="narrow-by-list"data-role="content" data-mage-init='
                            {
                                "accordion":
                                {
                                    "openedState": "active",
                                    "collapsible": true,
                                    "active": false,
                                    "multipleCollapsible": false
                                }
                            }'>
                        <?php
                            $wrapOptions = true;
                            endif;
                        ?>
                        <?php if ($filter->getItemsCount()): ?>
                            <?php
                            $title = "";
                            if ($filter->getRequestVar() == "price") {
                                $title = __("Filter"). " ";
                            }
                            $title .= $filter->getName();
                            ?>
                            <?php if ($filter->getRequestVar() == "cat" || $filter->getRequestVar() == "price") { ?>
                                <div data-role="collapsible" class="filter-options-item <?php if($filter->getRequestVar() == "price"){ echo "radioStyle"; } ?>">
                                    <div data-role="title" class="filter-options-title"><?= $block->escapeHtml(__($title)) ?></div>
                                    <div data-role="content" class="filter-options-content"><?= /* @noEscape */ $block->getChildBlock('renderer')->render($filter) ?></div>
                                </div>
                            <?php } ?>
                        <?php endif; ?>
                        <script>
                            require((
                                'jquery'
                            ), function ($) {
                                $('#layered-filter-block').addClass('filter-no-options');
                            });
                        </script>
<?php endforeach; ?>

Can we optimise it further?

configuration – What would cause slow disk access on an AWS EBS SQL Server? (PAGEIOLATCH_SH)

I have an EC2 instance (r5a.4xlarge) which should be able to do 2Gbps+ in EBS access. This machine has a 7TB mounted gp2 volume, with 16,000 IOPS, which is mounted and contains a SQL Server database on the H: drive. The database is about 5TB in size.

When running SQL Server commands (specifically, reading from the drive and writing to another drive), and monitoring the the volume throughput, on this volume / drive, commands are taking an incredibly long time to process and SQL Server is showing a PAGEIOLATCH_SH lock, with 34ms response times (other volumes are 1ms or 2ms).

Microsoft’s literature says this is a disk subsystem issue. We do not have this problem with other drives / volumes on this machine.

What needs to happen to get this from 34ms to < 2ms, like we are on the other drives? Something we’re not configuring properly?

media library – Want to sell images online on wordpress but slow image loading issues

I wish to sell images, videos and music online but if I add the media files in WordPress, the website becomes slow. IS it possible to add a library? where I can upload thousands of images and videos without slowing down my WordPress site and linking it to the website?

python – Where could I optmize this slow 3sat algorithm

i’m currently trying to solve this problem: https://open.kattis.com/problems/satisfiability

And I have this code:

import sys

cases = int(sys.stdin.readline())


def GetReverse(literal):
    if literal(0) == '~':
    return literal(1:)
    else:
        return '~' + literal


for i in range(cases):
    vars, clauses = map(int, sys.stdin.readline().split())

mySets = ()

firstClause = sys.stdin.readline().strip().split(" v ")

for c in firstClause:
    this = set()
    this.add(c)
    mySets.append(this)


for i in range(clauses-1):
    tempSets = ()
    currentClause = sys.stdin.readline().strip().split(" v ")

    for s in mySets:
        for literal in currentClause:

            if not s.__contains__(GetReverse(literal)):


                newset = s.copy()
                newset.add(literal)

                tempSets.append(newset)
    mySets = tempSets


if mySets:
    print("satisfiable")
else:
    print("unsatisfiable")

This code basically maintains “mySets” which is a list of sets, which all represent possible combinations of literals that could make the entire statement true.
every time we parse a new clause, we check if it’s negation exists already in a set, if it does, the set is not included.

for i in range(clauses-1):
tempSets = ()
currentClause = sys.stdin.readline().strip().split(" v ")

for s in mySets:
    for literal in currentClause:

        if not s.__contains__(GetReverse(literal)):


            newset = s.copy()
            newset.add(literal)

            tempSets.append(newset)
mySets = tempSets

It’s obvious that the problem lies somewhere here, indented forloops just arent great, but 3sat should be at least exponential anyway.
Could i do the same thing as I do here, using one less loop? thanks a lot

entities – Publishing Content is very slow

I noticed something on my site, whenever I press on publish in order to publish a content, the process takes around 2 to 3 minutes ! and if I edit a node and save the changes , the process is also really slow. There are no errors in the log messages . And when I wait for the 3 minutes, the content is published successfully. So the main issue is just being slow ..Any idea why?

8 – Node save slow with a field containing lots of paragraphs

I have a node (which uses revisions) that has a Paragraph field. It has around 80 Paragraphs referenced to it. When I save the node programmatically it’s very slow. It seems like the slow down is happening in the preSave() of the Paragraph field. I’m wondering if every referenced Paragraph is being loaded when the node is being saved? And if so is this normal functionality?

Could it just be bad design by myself that I created a node that has a field with 80+ Paragraphs referenced to it? Or is it legitimate to do it this way?

sql – wordpress slow query shown in query monitor

I have a slow query on a wordpress site. I believe it’s my subquery inside it for the ‘abbreviation’. How can I rewrite this to make it faster? I’m not having much luck. The query takes about 0.1219 seconds I have both the query and the explain below, my goal is to modify this query to make it execute faster, thanks.

This is the query:

SELECT
    wrapper_featured_colorways.id,
    wrapper_featured_colorways.design_name AS dname,
    wrapper_featured_colorways.designId,
    wrapper_featured_colorways.submodel_id,
    wrapper_featured_colorways.sled_image,
    wrapper_featured_colorways.sled_png,
    wrapper_featured_colorways.colorway_name,
    wrapper_featured_colorways.engineId,
    wrapper_featured_colorways.yearText,
    wrapper_submodels.model_id,
    wrapper_submodels.sub_name,
    wrapper_models.model_name,
    wrapper_chassis.id AS chassis_id,
    wrapper_chassis.chassis_name,
    wrapper_manufacturers.mf_name,
    wrapper_manufacturers.mf_id,
    a.guid AS svgPath,
    afx_posts.post_type,
    afx_posts.post_title,
    GROUP_CONCAT(
        wrapper_featured_colorway_colors.color_name
    ORDER BY
        wrapper_featured_colorway_colors.sort_order
    ) AS colors
FROM
    wrapper_featured_colorways
JOIN afx_posts a ON
    (
        a.post_parent = wrapper_featured_colorways.designId
    )
JOIN afx_posts ON(
        afx_posts.ID = wrapper_featured_colorways.designId
    )
JOIN afx_postmeta z ON
    (
        (z.meta_key = 'svg_image') AND(a.ID = z.meta_value)
    )
JOIN wrapper_submodels ON wrapper_featured_colorways.submodel_id = wrapper_submodels.id
JOIN wrapper_models ON wrapper_submodels.model_id = wrapper_models.id
JOIN wrapper_chassis ON wrapper_models.chassis_id = wrapper_chassis.id
JOIN wrapper_manufacturers ON wrapper_chassis.manufacturer_id = wrapper_manufacturers.mf_id
JOIN wrapper_featured_colorway_colors ON wrapper_featured_colorways.id = wrapper_featured_colorway_colors.colorway_id
WHERE
    wrapper_featured_colorways.deleted = 0
GROUP BY
    wrapper_featured_colorway_colors.colorway_id

This is the Explain:

EXPLAIN SELECT
    wrapper_featured_colorways.id,
    wrapper_featured_colorways.design_name AS dname,
    wrapper_featured_colorways.designId,
    wrapper_featured_colorways.submodel_id,
    wrapper_featured_colorways.sled_image,
    wrapper_featured_colorways.sled_png,
    wrapper_featured_colorways.colorway_name,
    wrapper_featured_colorways.engineId,
    wrapper_featured_colorways.yearText,
    wrapper_submodels.model_id,
    wrapper_submodels.sub_name,
    wrapper_models.model_name,
    wrapper_chassis.id AS chassis_id,
    wrapper_chassis.chassis_name,
    wrapper_manufacturers.mf_name,
    wrapper_manufacturers.mf_id,
    a.guid AS svgPath,
    afx_posts.post_type,
    afx_posts.post_title,
    GROUP_CONCAT(
        wrapper_featured_colorway_colors.color_name
    ORDER BY
        wrapper_featured_colorway_colors.sort_order
    ) AS colors
FROM
    wrapper_featured_colorways
JOIN afx_posts a ON
    (
        a.post_parent = wrapper_featured_colorway(...)


1   SIMPLE  wrapper_manufacturers   
    NULL
    ALL PRIMARY 
    NULL
    
    NULL
    
    NULL
    4   100.00  Using temporary; Using filesort 
1   SIMPLE  wrapper_featured_colorways  
    NULL
    ALL PRIMARY 
    NULL
    
    NULL
    
    NULL
    45  10.00   Using where; Using join buffer (Block Nested Loop)  
1   SIMPLE  wrapper_submodels   
    NULL
    eq_ref  PRIMARY PRIMARY 4   fxgraphi_v2019.wrapper_featured_colorways.submodel_id   1   100.00  Using where 
1   SIMPLE  wrapper_models  
    NULL
    eq_ref  PRIMARY PRIMARY 4   fxgraphi_v2019.wrapper_submodels.model_id   1   100.00  Using where 
1   SIMPLE  wrapper_chassis 
    NULL
    eq_ref  PRIMARY PRIMARY 4   fxgraphi_v2019.wrapper_models.chassis_id    1   10.00   Using where 
1   SIMPLE  afx_posts   
    NULL
    eq_ref  PRIMARY PRIMARY 8   fxgraphi_v2019.wrapper_featured_colorways.designId  1   100.00  Using index condition   
1   SIMPLE  z   
    NULL
    ref meta_key    meta_key    576 const   139 100.00  Using where 
1   SIMPLE  a   
    NULL
    eq_ref  PRIMARY,post_parent PRIMARY 8   fxgraphi_v2019.z.meta_value 1   10.00   Using index condition; Using where  
1   SIMPLE  wrapper_featured_colorway_colors    
    NULL
    ALL 
    NULL
    
    NULL
    
    NULL
    
    NULL
    1431    10.00   Using where; Using join buffer (Block Nested Loop)  

```