最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

【IT专家】多线程C程序在OS X上比Linux慢得多。

IT圈 admin 27浏览 0评论

2024年3月28日发(作者:校青曼)

本文由我司收集整编,推荐下载,如有疑问,请与我司联系

多线程C程序在OS X上比Linux慢得多。

I wrote this for an OS class assignment that I’ve already completed and handed in. I

posted this question yesterday, but due to “Academic Honesty” regulations I took it off

until after the submission deadline.

 我为一个OS类作业写了这个,我已经完成并交了。我昨天发布了这个问题,但

由于“学术诚信”的规定,我在提交截止日期后才将其删除。

  The object was to learn how to use critical sections. There is a data array with 100

monotonously increasing numbers, 0...99, and 40 threads that randomly swap two

elements 2,000,000 times each. Once a second a Checkergoes through and makes sure that

there is only one of each number (which means that no parallel access happened).

 目的是学习如何使用关键部分。有一个带有100个单调递增数字的数据数组,

0…99和40个线程,每个线程随机交换两个元素200万次。每秒钟检查一次,确保

每个数字中只有一个(这意味着没有并行访问发生)。

  Here were the Linux times:

 以下是Linux时代:

  real 0m5.102suser 0m5.087ssys 0m0.000s and the OS X times

 OS X乘以

  real 6m54.139suser 0m41.873ssys 6m43.792s I run a vagrant box with

ubuntu/trusty64 on the same machine that is running OS X. It is a quad-core i7 2.3Ghz (up

to 3.2Ghz) 2012 rMBP.

 我在运行OS x的同一台机器上运行一个带有ubuntu/trusty64的移动盒子。它是一

个四核i7 2.3Ghz(最高3.2Ghz) 2012 rMBP。

  If I understand correctly, sys is system overhead, which I have no control over, and

even then, 41s of user time suggests that perhaps the threads are running serially.

 如果我理解正确的话,sys是系统开销,我无法控制系统开销,即使这样,41s的

用户时间也表明线程可能是连续运行的。

2024年3月28日发(作者:校青曼)

本文由我司收集整编,推荐下载,如有疑问,请与我司联系

多线程C程序在OS X上比Linux慢得多。

I wrote this for an OS class assignment that I’ve already completed and handed in. I

posted this question yesterday, but due to “Academic Honesty” regulations I took it off

until after the submission deadline.

 我为一个OS类作业写了这个,我已经完成并交了。我昨天发布了这个问题,但

由于“学术诚信”的规定,我在提交截止日期后才将其删除。

  The object was to learn how to use critical sections. There is a data array with 100

monotonously increasing numbers, 0...99, and 40 threads that randomly swap two

elements 2,000,000 times each. Once a second a Checkergoes through and makes sure that

there is only one of each number (which means that no parallel access happened).

 目的是学习如何使用关键部分。有一个带有100个单调递增数字的数据数组,

0…99和40个线程,每个线程随机交换两个元素200万次。每秒钟检查一次,确保

每个数字中只有一个(这意味着没有并行访问发生)。

  Here were the Linux times:

 以下是Linux时代:

  real 0m5.102suser 0m5.087ssys 0m0.000s and the OS X times

 OS X乘以

  real 6m54.139suser 0m41.873ssys 6m43.792s I run a vagrant box with

ubuntu/trusty64 on the same machine that is running OS X. It is a quad-core i7 2.3Ghz (up

to 3.2Ghz) 2012 rMBP.

 我在运行OS x的同一台机器上运行一个带有ubuntu/trusty64的移动盒子。它是一

个四核i7 2.3Ghz(最高3.2Ghz) 2012 rMBP。

  If I understand correctly, sys is system overhead, which I have no control over, and

even then, 41s of user time suggests that perhaps the threads are running serially.

 如果我理解正确的话,sys是系统开销,我无法控制系统开销,即使这样,41s的

用户时间也表明线程可能是连续运行的。

发布评论

评论列表 (0)

  1. 暂无评论